可完全正确加载模型以及场景的代码

This commit is contained in:
hyzboy 2020-06-20 01:26:33 +08:00
parent 39c8b7d56e
commit 4832e23573
3 changed files with 67 additions and 2 deletions

@ -1 +1 @@
Subproject commit 9b1975a8a5c74dfc5189b4d7f23d155b6e15cca8
Subproject commit 984d9698ef873a08f0c99579e8a9b4bf15e5ce5f

View File

@ -167,6 +167,64 @@ namespace hgl
return(true);
}
SceneNodeData *LoadNode(const int level)
{
#ifdef _DEBUG
AutoDeleteArray<char> spaces=new char[level+1];
memset(spaces,' ',level);
spaces[level]=0;
#endif//_DEBUG
SceneNodeData *node=new SceneNodeData;
memcpy(&(node->local_matrix),sp,sizeof(Matrix4f));
sp+=sizeof(Matrix4f);
{
const uint8 name_len=*sp++;
node->name.SetString((char *)sp,name_len);
sp+=name_len;
LOG_INFO(spaces+UTF8String("Node name: ")+node->name);
}
{
node->mesh_count=*(uint32 *)sp;
sp+=sizeof(uint32);
if(node->mesh_count>0)
{
node->mesh_index=(const uint32 *)sp;
#ifdef _DEBUG
const uint32 *mi=node->mesh_index;
for(uint i=0;i<node->mesh_count;i++)
LOG_INFO(spaces+UTF8String(" ")+UTF8String::valueOf(i)+UTF8String(" : ")+md->mesh_name[*mi++]);
#endif//_DEBUG
sp+=node->mesh_count*sizeof(uint32);
}
}
{
const uint32 child_count=*(uint32 *)sp;
sp+=sizeof(uint32);
if(child_count>0)
{
LOG_INFO(spaces+UTF8String("Sub-node Count: ")+UTF8String::valueOf(child_count));
for(uint i=0;i<child_count;i++)
node->sub_nodes.Add(LoadNode(level+1));
}
}
return node;
}
public:
LoadModelData(uint8 *source,const uint8 *s)
@ -204,6 +262,12 @@ namespace hgl
md->mesh_list.Add(mesh);
}
LOG_INFO(OS_TEXT("Load Scene Tree"));
Load(md->bounding_box);
md->root_node=LoadNode(1);
return(true);
}
};//struct LoadModelData

View File

@ -14,7 +14,8 @@ namespace hgl
Matrix4f local_matrix;
List<uint32> mesh_index;
uint32 mesh_count;
const uint32 *mesh_index;
ObjectList<SceneNodeData> sub_nodes;
};//struct SceneNodeData