第二人生的源码分析(十六)保存人物角色的XML文件

2019-12-05 07:05:09 来源: 枣庄信息港

前面介绍怎么样从文件里读取Mesh数据,那么怎么样知道数据从那里读取回来呢?这些信息又是记录在那里呢?现在就来分析这方面的问题。

其实在第二人生里把这些信息保存在XML文件里的,可以在第二人生的目录character里找到文件avatar_lad.xml,这个文件就记录了人物角色组成信息。比如每个部位的组成文件名称,就可以通过下面XML片段可以找到:

<mesh

type="hairMesh"

lod="1"

file_name="avatar_hair_1.llm"

min_pixel_width="160"

reference="avatar_hair.llm">

</mesh>

<mesh

type="hairMesh"

lod="2"

file_name="avatar_hair_2.llm"

min_pixel_width="80"

reference="avatar_hair.llm">

</mesh>

<mesh

type="hairMesh"

lod="3"

file_name="avatar_hair_3.llm"

min_pixel_width="40"

reference="avatar_hair.llm">

</mesh>

<mesh

type="hairMesh"

lod="4"

file_name="avatar_hair_4.llm"

min_pixel_width="20"

reference="avatar_hair.llm">

</mesh>

<mesh

type="hairMesh"

lod="5"

file_name="avatar_hair_5.llm"

min_pixel_width="0"

reference="avatar_hair.llm">

</mesh>

<mesh

type="headMesh"

lod="0"

file_name="avatar_head.llm"

min_pixel_width="320">

分析这个XML文件的代码函数LLVOAvatar::initClass(),如下:

#001 void LLVOAvatar::initClass()

#002 {

#003 LLVOAvatar::sMaxOtherAvatarsToComposite = gSavedSettings.getS32("AvatarCompositeLimit");

#004

#005 char xmlFile[MAX_PATH]; /* Flawfinder: ignore */

#006

#007 snprintf(xmlFile, MAX_PATH, "%s_lad.xml", gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,AVATAR_DEFAULT_CHAR).c_str()); /* Flawfinder:

#008 ignore */

获取文件路径名称。

#009 BOOL success = sXMLTree.parseFile( xmlFile, FALSE );

分析这个XML文件数据。

#010 if (!success)

#011 {

#012 llerrs << "Problem reading avatar configuration file:" << xmlFile << llendl;

#013 }

#014

#015 // now sanity check xml file

#016 LLXmlTreeNode* root = sXMLTree.getRoot();

#017 if (!root)

#018 {

#019 llerrs << "No root node found in avatar configuration file: " << xmlFile << llendl;

#020 return;

#021 }

#022

#023 //-------------------------------------------------------------------------

#024 // <linden_avatar version="1.0"> (root)

#025 //-------------------------------------------------------------------------

#026 if( !root->hasName( "linden_avatar" ) )

#027 {

#028 llerrs << "Invalid avatar file header: " << xmlFile << llendl;

#029 }

#030

#031 LLString version;

#032 static LLStdStringHandle version_string = LLXmlTree::addAttributeString("version");

#033 if( !root->getFastAttributeString( version_string, version ) || (version != "1.0") )

#034 {

#035 llerrs << "Invalid avatar file version: " << version << " in file: " << xmlFile << llendl;

#036 }

#037

#038 S32 wearable_def_version = 1;

#039 static LLStdStringHandle wearable_definition_version_string = LLXmlTree::addAttributeString("wearable_definition_version");

#040 root->getFastAttributeS32( wearable_definition_version_string, wearable_def_version );

#041 LLWearable::setCurrentDefinitionVersion( wearable_def_version );

#042

#043 LLString mesh_file_name;

#044

#045 LLXmlTreeNode* skeleton_node = root->getChildByName( "skeleton" );

#046 if (!skeleton_node)

#047 {

#048 llerrs << "No skeleton in avatar configuration file: " << xmlFile << llendl;

#049 return;

#050 }

#051

#052 LLString skeleton_file_name;

#053 static LLStdStringHandle file_name_string = LLXmlTree::addAttributeString("file_name");

#054 if (!skeleton_node->getFastAttributeString(file_name_string, skeleton_file_name))

#055 {

#056 llerrs << "No file name in skeleton node in avatar config file: " << xmlFile << llendl;

#057 }

#058

#059 std::string skeleton_path;

#060 skeleton_path = gDirUtilp->getExpandedFilename(LL_PATH_CHARACTER,skeleton_file_name);

#061 if (!parseSkeletonFile(skeleton_path))

#062 {

#063 llerrs << "Error parsing skeleton file: " << skeleton_path << llendl;

#064 }

#065

#066 // Process XML data

#067

#068 // avatar_skeleton.xml

#069 llassert(!sSkeletonInfo);

#070 sSkeletonInfo = new LLVOAvatarSkeletonInfo;

#071 if (!sSkeletonInfo->parseXml(sSkeletonXMLTree.getRoot()))

#072 {

#073 llerrs << "Error parsing skeleton XML file: " << skeleton_path << llendl;

#074 }

#075 // parse avatar_lad.xml

#076 llassert(!sAvatarInfo);

#077 sAvatarInfo = new LLVOAvatarInfo;

#078 if (!sAvatarInfo->parseXmlSkeletonNode(root))

#079 {

#080 llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;

#081 }

#082 if (!sAvatarInfo->parseXmlMeshNodes(root))

#083 {

#084 llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;

#085 }

#086 if (!sAvatarInfo->parseXmlColorNodes(root))

#087 {

#088 llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;

#089 }

#090 if (!sAvatarInfo->parseXmlLayerNodes(root))

#091 {

#092 llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;

#093 }

#094 if (!sAvatarInfo->parseXmlDriverNodes(root))

#095 {

#096 llerrs << "Error parsing skeleton node in avatar XML file: " << skeleton_path << llendl;

#097 }

#098 }

查看本文来源

北仑大港医院医生
云梦县人民医院怎么样
广东治疗子宫内膜炎费用
长沙市治疗癫痫病的医院
治疗性功能障碍方法
本文标签: