首页 » .NET » Krpano学习:在C#中修改全景场景属性(C#操作全景vtour.xml文件

Krpano学习:在C#中修改全景场景属性(C#操作全景vtour.xml文件

原文 http://blog.csdn.net/u013719339/article/details/79253481

2018-02-05 02:00:15阅读(332)

  搜索在C#中操作xml可找到很多相关教程,此处就不细说了。krpano的全景xml文件和传统xml文件的不同仅在于它们的根不一样,vtour.xml文件的根为:

<krpano version="1.19" title="">
</krpano>

且每个全景一般都包含有include、skin_settings、action这三个子元素,之后才是场景scene,scene里有自己的属性,还有view、hotspot等子元素。
用两张全景照片在MAKE VTOUR (NORMAL) droplet.bat上生成全景,则xml文件为

<krpano version="1.19" title="Virtual Tour">
    <include url="skin/vtourskin.xml" />
    <!-- customize skin settings: maps, gyro, webvr, thumbnails, tooltips, layout, design, ... -->
    <skin_settings maps="false"
                   maps_type="google"
                   maps_bing_api_key=""
                   maps_google_api_key=""
                   maps_zoombuttons="false"
                   gyro="true"
                   webvr="true"
                   webvr_gyro_keeplookingdirection="false"
                   webvr_prev_next_hotspots="true"
                   littleplanetintro="false"
                   title="true"
                   thumbs="true"
                   thumbs_width="120" thumbs_height="80" thumbs_padding="10" thumbs_crop="0|40|240|160"
                   thumbs_opened="false"
                   thumbs_text="false"
                   thumbs_dragging="true"
                   thumbs_onhoverscrolling="false"
                   thumbs_scrollbuttons="false"
                   thumbs_scrollindicator="false"
                   thumbs_loop="false"
                   tooltips_buttons="false"
                   tooltips_thumbs="false"
                   tooltips_hotspots="false"
                   tooltips_mapspots="false"
                   deeplinking="false"
                   loadscene_flags="MERGE"
                   loadscene_blend="OPENBLEND(0.5, 0.0, 0.75, 0.05, linear)"
                   loadscene_blend_prev="SLIDEBLEND(0.5, 180, 0.75, linear)"
                   loadscene_blend_next="SLIDEBLEND(0.5,   0, 0.75, linear)"
                   loadingtext="loading..."
                   layout_width="100%"
                   layout_maxwidth="814"
                   controlbar_width="-24"
                   controlbar_height="40"
                   controlbar_offset="20"
                   controlbar_offset_closed="-40"
                   controlbar_overlap.no-fractionalscaling="10"
                   controlbar_overlap.fractionalscaling="0"
                   design_skin_images="vtourskin.png"
                   design_bgcolor="0x2D3E50"
                   design_bgalpha="0.8"
                   design_bgborder="0"
                   design_bgroundedge="1"
                   design_bgshadow="0 4 10 0x000000 0.3"
                   design_thumbborder_bgborder="3 0xFFFFFF 1.0"
                   design_thumbborder_padding="2"
                   design_thumbborder_bgroundedge="0"
                   design_text_css="color:#FFFFFF; font-family:Arial;"
                   design_text_shadow="1"
                   />
    <!-- startup action - load the first scene -->
    <action name="startup" autorun="onstart">
        if(startscene === null OR !scene[get(startscene)], copy(startscene,scene[0].name); );
        loadscene(get(startscene), null, MERGE);
        if(startactions !== null, startactions() );
    </action>
    <scene name="scene_Ghm1_color" title="Ghm1_color" onstart="" thumburl="panos/Ghm1_color.tiles/thumb.jpg" lat="" lng="" heading="">
        <view hlookat="0" vlookat="0" fovtype="MFOV" fov="120" maxpixelzoom="2.0" fovmin="70" fovmax="140" limitview="range" vlookatmin="-54.349" vlookatmax="54.349" />
        <preview url="panos/Ghm1_color.tiles/preview.jpg" />
        <image>
            <cube url="panos/Ghm1_color.tiles/pano_%s.jpg" />
            <cube url="panos/Ghm1_color.tiles/mobile/pano_%s.jpg" devices="mobile" />
        </image>
        <!-- place your scene hotspots here -->
    </scene>
    <scene name="scene_Ghm2_color" title="Ghm2_color" onstart="" thumburl="panos/Ghm2_color.tiles/thumb.jpg" lat="" lng="" heading="">
        <view hlookat="0" vlookat="0" fovtype="MFOV" fov="120" maxpixelzoom="2.0" fovmin="70" fovmax="140" limitview="range" vlookatmin="-54.349" vlookatmax="54.349" />
        <preview url="panos/Ghm2_color.tiles/preview.jpg" />
        <image>
            <cube url="panos/Ghm2_color.tiles/pano_%s.jpg" />
            <cube url="panos/Ghm2_color.tiles/mobile/pano_%s.jpg" devices="mobile" />
        </image>
        <!-- place your scene hotspots here -->
    </scene>
</krpano>
在进行操作前要引用命名空间
using System.Xml;
加载xml文件及保存
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlpath); //xml绝对路径 加载xml文件
RenameXmlTitle(xmlDoc, “Ghm1_color”, “Ghm1”); //修改title
xmlDoc.Save(xmlpath); //保存xml文件
修改场景显示名称
/// <summary>
/// 修改场景显示名称title
/// </summary>
/// <param name="xmlDoc">xml文件名称</param>
/// <param name="sceneid">场景唯一名称name</param>
/// <param name="scenename">scenename</param>
/// <returns>成功/失败</returns>
private string RenameXmlTitle(XmlDocument xmlDoc, string sceneid, string scenename)
{
    try
    {
        XmlNode renameNode = xmlDoc.DocumentElement.SelectSingleNode("/krpano/scene[@name='scene_" + sceneid + "']");
        XmlElement element = (XmlElement)renameNode;
        element.SetAttribute("title", scenename);
        return "success";
    }
    catch (Exception ex)
    {
        return "failed";
    }
}

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹