コード例 #1
0
ファイル: frmMain.cs プロジェクト: xuyibin/maptiledownloader
        public frmMain()
        {
            InitializeComponent();
            MapLayer.SetAbstractGraphicsFactory(NETGraphicsFactory.getInstance());
            localMapTileFileReader = new MapTileVectorDataSource(@"D:\nanjing\Nanjing.pst");
            GeoSet getSet = localMapTileFileReader.GetGeoSet();

            graphics   = Graphics.FromImage(mapImage);
            drawFont   = new Font("Arial", 16, FontStyle.Bold);
            drawBrush  = new SolidBrush(Color.Red);
            pen        = new Pen(Color.Red);
            greenColor = Color.FromArgb(120, Color.Blue);
            fillBrush  = new SolidBrush(greenColor);
            getSet.GetMapMapFeatureLayer("POI.lyr").FontColor          = 0x0000FF;
            getSet.GetMapMapFeatureLayer("POI.lyr").FontName           = "楷体";
            getSet.GetMapMapFeatureLayer("LandMark.lyr").FontColor     = 0;
            getSet.GetMapMapFeatureLayer("LandMark.lyr").FontName      = "Arial";
            getSet.GetMapMapFeatureLayer("Adm_LandMark.lyr").FontColor = 0;
            getSet.GetMapMapFeatureLayer("Adm_LandMark.lyr").FontName  = "Arial";
            getSet.GetMapMapFeatureLayer("Road.lyr").FontColor         = 16711680;
            getSet.GetMapMapFeatureLayer("Road.lyr").FontName          = "楷体";
            getSet.GetMapMapFeatureLayer("RailWay.lyr").FontColor      = 0;
            getSet.GetMapMapFeatureLayer("RailWay.lyr").FontName       = "Arial";
            getSet.GetMapMapFeatureLayer("Landuse.lyr").FontColor      = 0;
            getSet.GetMapMapFeatureLayer("Landuse.lyr").FontName       = "Arial";
            getSet.GetMapMapFeatureLayer("Block.lyr").FontColor        = 0;
            getSet.GetMapMapFeatureLayer("Landuse.lyr").FontName       = "Arial";
            getSet.GetMapMapFeatureLayer("Adm_Area.lyr").FontColor     = 16711680;
            getSet.GetMapMapFeatureLayer("Adm_Area.lyr").FontName      = "宋体";
            mapTileDownloadManager = new MapTileDownloadManager(this);
            mapFileIndex           = new FileStream("world.ind", FileMode.Open);
            mapFileData            = new FileStream("world.dat", FileMode.Open);
            MapIndexReader         = new BinaryReader(mapFileIndex);
            MapDataReader          = new BinaryReader(mapFileData);
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    SelectedMapIndex[i, j] = false;
                }
            }
            SelectedMapIndex[0, 0] = true;
            DrawMapImages();
            cboMapType.SelectedIndex = 12;
            managerThread            = new Thread(new ThreadStart(mapTileDownloadManager.ProcessTaskList));
            managerThread.Start();
        }
コード例 #2
0
        //public MapTileVectorDataSource(string url)
        //{
        //    Uri = url;
        //    _geoStream = new FileStream(url, FileMode.Open);
        //    byte[] bufferGeo = new byte[_geoStream.Length];
        //    _geoStream.Read(bufferGeo, 0, bufferGeo.Length);
        //    _geoStream.Close();
        //    MemoryStream baisGeo = new MemoryStream(bufferGeo);
        //    _getSet = new GeoSet(new BinaryReader(baisGeo));
        //    string filePath = Path.GetDirectoryName(url);
        //    string[] layerNames = _getSet.GetLayerNames();
        //    _layerStreams = new FileStream[layerNames.Length];
        //    for (int i = 0; i < layerNames.Length; i++)
        //    {
        //        string layerName = filePath + "\\" + layerNames[i];
        //        _layerStreams[i] = new FileStream(layerName, FileMode.Open);
        //        MapFeatureLayer layer = new MapFeatureLayer(new BinaryReader(_layerStreams[i]));
        //        layer.FontColor = 0x000000;
        //        GeoSet.MapFeatureLayerInfo layerInfo = _getSet.GetMapMapFeatureLayerInfo(layerNames[i]);
        //        if (layerInfo != null)
        //        {
        //            layer.ZoomLevel = layerInfo.ZoomLevel;
        //            layer.ZoomMin = layerInfo.ZoomMin;
        //            layer.ZoomMax = layerInfo.ZoomMax;
        //            layer.Description = layerInfo.Description;
        //            layer.Visible = layerInfo.Visible;
        //            layer.LayerName = layerInfo.LayerName;
        //        }
        //        _getSet.AddMapFeatureLayer(layer);
        //    }

        //    _vectorMapRenderer = new VectorMapRenderer(_getSet);
        //    Font font = new Font(FontFamily.GenericSansSerif, 13, FontStyle.Regular);
        //    IFont newFont = MapLayer.GetAbstractGraphicsFactory().CreateFont(font);
        //    _vectorMapRenderer.SetFont(newFont);
        //    _getSet.Open();

        //}


        public MapTileVectorDataSource(string url)
        {
            Uri        = url;
            _geoStream = new FileStream(url, FileMode.Open);
            byte[] bufferGeo = new byte[_geoStream.Length];
            _geoStream.Read(bufferGeo, 0, bufferGeo.Length);
            _geoStream.Close();
            MemoryStream baisGeo = new MemoryStream(bufferGeo);

            _getSet = new GeoSet();
            string filePath = @"C:\shenjing\map";

            string[] layerNames = new string[] { "3.lyr", "1.lyr", "2.lyr" };
            _layerStreams = new FileStream[layerNames.Length];
            for (int i = 0; i < layerNames.Length; i++)
            {
                string layerName = filePath + "\\" + layerNames[i];
                _layerStreams[i] = new FileStream(layerName, FileMode.Open);
                MapFeatureLayer layer = new MapFeatureLayer(new BinaryReader(_layerStreams[i]));
                layer.FontColor = 0x000000;
                GeoSet.MapFeatureLayerInfo layerInfo = _getSet.GetMapMapFeatureLayerInfo(layerNames[i]);
                if (layerInfo != null)
                {
                    layer.ZoomLevel   = layerInfo.ZoomLevel;
                    layer.ZoomMin     = layerInfo.ZoomMin;
                    layer.ZoomMax     = layerInfo.ZoomMax;
                    layer.Description = layerInfo.Description;
                    layer.Visible     = layerInfo.Visible;
                    layer.LayerName   = layerInfo.LayerName;
                }
                _getSet.AddMapFeatureLayer(layer);
            }

            _vectorMapRenderer = new VectorMapRenderer(_getSet);
            Font  font    = new Font(FontFamily.GenericSansSerif, 13, FontStyle.Regular);
            IFont newFont = MapLayer.GetAbstractGraphicsFactory().CreateFont(font);

            _vectorMapRenderer.SetFont(newFont);
            _getSet.Open();
        }
コード例 #3
0
        public void InitVectorMap()
        {
            MapTileVectorDataSource localMapTileFileReader = new MapTileVectorDataSource(@"c:\nanjing\Nanjing.pst");
            GeoSet getSet = localMapTileFileReader.GetGeoSet();

            //getSet.GetMapMapFeatureLayer("POI.lyr").FontColor = 0x0000FF;
            //getSet.GetMapMapFeatureLayer("POI.lyr").FontName = "楷体";
            //getSet.GetMapMapFeatureLayer("LandMark.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("LandMark.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("Adm_LandMark.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("Adm_LandMark.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("Road.lyr").FontColor = 16711680;
            //getSet.GetMapMapFeatureLayer("Road.lyr").FontName = "楷体";
            //getSet.GetMapMapFeatureLayer("RailWay.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("RailWay.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("Landuse.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("Landuse.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("Block.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("Landuse.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("Adm_Area.lyr").FontColor = 16711680;
            //getSet.GetMapMapFeatureLayer("Adm_Area.lyr").FontName = "宋体";
            //getSet.GetMapMapFeatureLayer("1.lyr").FontColor = 0x0000FF;
            //getSet.GetMapMapFeatureLayer("1.lyr").FontName = "楷体";
            //getSet.GetMapMapFeatureLayer("2.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("2.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("3.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("3.lyr").FontName = "Arial";
            //getSet.GetMapMapFeatureLayer("4.lyr").FontColor = 16711680;
            //getSet.GetMapMapFeatureLayer("4.lyr").FontName = "楷体";
            //getSet.GetMapMapFeatureLayer("5.lyr").FontColor = 0;
            //getSet.GetMapMapFeatureLayer("5.lyr").FontName = "Arial";

            // VectorMapRenderer vectorMapRenderer = new VectorMapRenderer(getSet);
            _mapTileDownloadManager = new MapTileDownloadManager(this, localMapTileFileReader);

            // getSet.Open();
        }
コード例 #4
0
    private static void convertMaterials(MeshRenderer ren, Model mdl, GameObject tgt)
    {
        ModelModifiers        model_trick = mdl.trck_node;
        GeometryModifiersData geom_trick  = mdl.src_mod;
        RuntimeData           rd          = RuntimeData.get();
        MaterialDescriptor    descriptor;

        string model_base_name = mdl.name.Split(new[] { "__" }, StringSplitOptions.None)[0];
        string mesh_path       = mdl.geoset.full_geo_path;
        int    obj_lib_idx     = mesh_path.IndexOf("object_library");

        if (obj_lib_idx != -1)
        {
            mesh_path = "Assets/Materials/" + mesh_path.Substring(obj_lib_idx);
        }
        string material_base_path = mesh_path + "/" + Path.GetFileNameWithoutExtension(mdl.name);

        if (mdl.name == "Crate1_med_Wood__TintCrates")
        {
            Debug.LogFormat("Crate {0}", mdl.BlendMode.ToString());
        }
        if (model_trick != null && model_trick._TrickFlags.HasFlag(TrickFlags.ColorOnly))
        {
//        result = result.Clone(result.GetName()+"Colored");
//        result.SetShaderParameter("MatDiffColor",Vector4(1.0, 1.0, 0.2f, 1.0f));
        }

        // Select material based on the model blend state
        // Modify material based on the applied model tricks
        Color onlyColor;
        Color tint1    = new Color(1, 1, 1, 1); // Shader Constant 0
        Color tint2    = new Color(1, 1, 1, 1); // Shader Constant 1
        float alphaRef = 0.0f;

        descriptor.depthWrite    = true;
        descriptor.isAdditive    = false;
        descriptor.targetCulling = UnityEngine.Rendering.CullMode.Back;
        descriptor.depthTest     = CompareFunction.LessEqual;
        descriptor.targetCulling = UnityEngine.Rendering.CullMode.Back;

        string shader_to_use = "";

        if (null != model_trick && model_trick._TrickFlags != 0)
        {
            var tflags = model_trick._TrickFlags;
            if (tflags.HasFlag(TrickFlags.Additive))
            {
                descriptor.isAdditive = true;
            }

            if (tflags.HasFlag(TrickFlags.ColorOnly))
            {
                onlyColor = model_trick.TintColor0;
            }
            if (tflags.HasFlag(TrickFlags.DoubleSided))
            {
                descriptor.targetCulling = UnityEngine.Rendering.CullMode.Off;
            }
            if (tflags.HasFlag(TrickFlags.NoZTest))
            {
                // simulate disabled Z test
                descriptor.depthTest = CompareFunction.Always;
                //depthTest = CompareFunction.Always;
                descriptor.depthWrite = false;
            }

            if (tflags.HasFlag(TrickFlags.NoZWrite))
            {
                descriptor.depthWrite = false;
            }
            if (tflags.HasFlag(TrickFlags.SetColor))
            {
                tint1   = model_trick.TintColor0;
                tint2   = model_trick.TintColor1;
                tint1.a = 1.0f;
                tint2.a = 1.0f;
            }

            if (tflags.HasFlag(TrickFlags.ReflectTex0) || tflags.HasFlag(TrickFlags.ReflectTex1))
            {
                shader_to_use = "Custom/ReflectGen";
                if (mdl.flags.HasFlag(ModelFlags.OBJ_CUBEMAP))
                {
                    Debug.Log("Unhandled Cubemap");
                }
            }

            if (tflags.HasFlag(TrickFlags.AlphaRef))
            {
                //qDebug() << "Unhandled alpha ref";
                alphaRef = geom_trick.AlphaRef;
            }

            if (tflags.HasFlag(TrickFlags.TexBias))
            {
                Debug.Log("Unhandled TexBias");
            }
        }

        CompareFunction depthTest     = CompareFunction.LessEqual;
        TextureWrapper  whitetex      = GeoSet.loadTexHeader("white");
        var             pixel_defines = new List <string>();

        pixel_defines.Add("DIFFMAP");
        pixel_defines.Add("ALPHAMASK");
        switch (mdl.BlendMode)
        {
        case CoHBlendMode.MULTIPLY:
            pixel_defines.Add("COH_MULTIPLY");
            break;

        case CoHBlendMode.MULTIPLY_REG:
            if (!descriptor.depthWrite && descriptor.isAdditive)
            {
                descriptor.targetCulling = UnityEngine.Rendering.CullMode.Off;
            }

            pixel_defines.Add("COH_MULTIPLY");
            break;

        case CoHBlendMode.COLORBLEND_DUAL:
            pixel_defines.Add("COH_COLOR_BLEND_DUAL");
            break;

        case CoHBlendMode.ADDGLOW:
            pixel_defines.Add("COH_ADDGLOW");
            break;

        case CoHBlendMode.ALPHADETAIL:
            pixel_defines.Add("COH_ALPHADETAIL");
            break;

        case CoHBlendMode.BUMPMAP_MULTIPLY:
            pixel_defines.Add("COH_MULTIPLY");
            break;

        case CoHBlendMode.BUMPMAP_COLORBLEND_DUAL:
            pixel_defines.Add("COH_COLOR_BLEND_DUAL");
            break;
        }

        if (mdl.flags.HasFlag(ModelFlags.OBJ_TREE))
        {
            shader_to_use = "CoH/Vegetation";
            alphaRef      = 0.4f;
            tint1.a       = 254.0f / 255.0f;
        }

        Material[] materials = new Material[mdl.texture_bind_info.Count];
        int        idx       = 0;

        Tools.EnsureDirectoryExists(material_base_path);
        var sup = tgt.GetComponent <ModelNodeMods>();

        sup.GeomTricks = geom_trick;
        VBOPointers vbo      = mdl.vbo;
        Shader      selected = null;

        if (descriptor.isAdditive)
        {
            if (shader_to_use == "Custom/ReflectGen")
            {
                selected = Shader.Find("Custom/ReflectGen");
            }
            else
            {
                selected = Shader.Find("Unlit/Additive");
            }
        }
        else
        {
            if (!String.IsNullOrEmpty(shader_to_use))
            {
                selected = Shader.Find(shader_to_use);
            }
            else
            {
                selected = Shader.Find("CoH/CoHMult");
            }
        }

        sup.TexWrappers = vbo.assigned_textures;

        foreach (TextureWrapper wrap in vbo.assigned_textures)
        {
            string   path_material_name = String.Format("{0}/{1}_{2}.mat", material_base_path, idx, descriptor.GetHashCode());
            Material available          = AssetDatabase.LoadAssetAtPath <Material>(path_material_name);
            if (available == null)
            {
                if (wrap != null)
                {
                    TextureWrapper detail = null;
                    if (!String.IsNullOrEmpty(wrap.detailname))
                    {
                        detail = GeoSet.loadTexHeader(wrap.detailname);
                    }


                    Material mat = new Material(selected);
                    mat.enableInstancing = true;
                    mat.SetColor("_Color", tint1);
                    mat.SetColor("_Color2", tint2);
                    mat.SetFloat("_AlphaRef", alphaRef);
                    mat.SetInt("_CoHMod", (int)mdl.BlendMode);

                    mat.SetTexture("_MainTex", wrap.tex);
                    if (detail != null)
                    {
                        mat.SetTexture("_Detail", detail.tex);
                    }
                    mat.SetInt("_ZWrite", descriptor.depthWrite ? 1 : 0);
                    mat.SetInt(ZTest, (int)descriptor.depthTest);
                    mat.SetInt(CullMode, (int)descriptor.targetCulling);
                    mat.SetTextureScale(MainTex, wrap.scaleUV1);
                    mat.SetTextureScale(Detail, wrap.scaleUV0);
                    AssetDatabase.CreateAsset(mat, path_material_name);
                    AssetDatabase.SaveAssets();
                    available = AssetDatabase.LoadAssetAtPath <Material>(path_material_name);
                }
            }
            materials[idx++] = available;
        }

        if (mdl.flags.HasFlag(ModelFlags.OBJ_HIDE))
        {
            ren.enabled = false;
        }

        ren.sharedMaterials = materials;
    }
コード例 #5
0
 public void Parse(GameBitBuffer buffer)
 {
     dwFlags = buffer.ReadInt(32);
     nBoneCount = buffer.ReadInt(32);
     serBoneStructure = new SerializeData();
     serBoneStructure.Parse(buffer);
     Field3 = new DT_VARIABLEARRAY();
     Field3.Parse(buffer);
     Field4 = new LookAtData();
     Field4.Parse(buffer);
     Field5 = buffer.ReadInt(32);
     Field6 = new DT_VARIABLEARRAY();
     Field6.Parse(buffer);
     serBonePulses = new SerializeData();
     serBonePulses.Parse(buffer);
     Field8 = new GeoSet[2];
     for(int i = 0;i < _Field8.Length;i++)
     {
         _Field8[i] = new GeoSet();
         _Field8[i].Parse(buffer);
     }
     Field9 = new Sphere();
     Field9.Parse(buffer);
     nCollisionCapsuleCount = buffer.ReadInt(32);
     serCollisionCapsules = new SerializeData();
     serCollisionCapsules.Parse(buffer);
     Field12 = new DT_VARIABLEARRAY();
     Field12.Parse(buffer);
     nHardpointCount = buffer.ReadInt(32);
     serHardpoints = new SerializeData();
     serHardpoints.Parse(buffer);
     Field15 = new DT_VARIABLEARRAY();
     Field15.Parse(buffer);
     Field16 = new Vector3D();
     Field16.Parse(buffer);
     tOctreeVisualMesh = new Octree();
     tOctreeVisualMesh.Parse(buffer);
     aabbBounds = new AABB();
     aabbBounds.Parse(buffer);
     nLoopConstraintCount = buffer.ReadInt(32);
     serLoopConstraints = new SerializeData();
     serLoopConstraints.Parse(buffer);
     Field21 = new DT_VARIABLEARRAY();
     Field21.Parse(buffer);
     uRagdollDegrade = buffer.ReadInt(32);
     Field23 = buffer.ReadCharArray(256);
     Field24 = buffer.ReadCharArray(256);
     Field25 = buffer.ReadCharArray(256);
     Field26 = buffer.ReadCharArray(256);
     Field27 = buffer.ReadInt(32);
     Field28 = buffer.ReadFloat32();
     Field29 = buffer.ReadInt(32);
 }