forked from Mirrors/openclonk
Fixed mesh loading
parent
3d359840a1
commit
a3f1ccf66e
|
@ -129,6 +129,10 @@ public:
|
|||
class StdMeshMatManager
|
||||
{
|
||||
public:
|
||||
// Remove all materials from manager. Make sure there is no StdMesh
|
||||
// referencing any out there before calling this.
|
||||
void Clear();
|
||||
|
||||
// Parse a material script file, and add the materials to the manager.
|
||||
// filename may be NULL if the source is not a file. It will only be used
|
||||
// for error messages.
|
||||
|
|
|
@ -47,7 +47,7 @@ private:
|
|||
StdMeshXML::StdMeshXML(const char* filename, const char* xml_data):
|
||||
FileName(filename)
|
||||
{
|
||||
Document.Parse(filename);
|
||||
Document.Parse(xml_data);
|
||||
if(Document.Error())
|
||||
throw StdMeshError(StdStrBuf(Document.ErrorDesc()), FileName.getData(), Document.ErrorRow());
|
||||
}
|
||||
|
@ -338,6 +338,11 @@ void StdMesh::InitXML(const char* filename, const char* xml_data, StdMeshSkeleto
|
|||
TiXmlElement* submesh_elem = mesh.RequireFirstChild(submeshes_elem, "submesh");
|
||||
TiXmlElement* geometry_elem = mesh.RequireFirstChild(submesh_elem, "geometry");
|
||||
|
||||
const char* material = mesh.RequireStrAttribute(submesh_elem, "material");
|
||||
Material = manager.GetMaterial(material);
|
||||
if(!Material)
|
||||
mesh.Error(FormatString("There is no such material named '%s'", material), submesh_elem);
|
||||
|
||||
int VertexCount = mesh.RequireIntAttribute(geometry_elem, "vertexcount");
|
||||
Vertices.resize(VertexCount);
|
||||
|
||||
|
@ -557,7 +562,7 @@ void StdMesh::InitXML(const char* filename, const char* xml_data, StdMeshSkeleto
|
|||
|
||||
TiXmlElement* translate_elem = skeleton.RequireFirstChild(keyframe_elem, "translate");
|
||||
TiXmlElement* rotate_elem = skeleton.RequireFirstChild(keyframe_elem, "rotate");
|
||||
TiXmlElement* scale_elem = skeleton.RequireFirstChild(scale_elem, "scale");
|
||||
TiXmlElement* scale_elem = skeleton.RequireFirstChild(keyframe_elem, "scale");
|
||||
TiXmlElement* axis_elem = skeleton.RequireFirstChild(rotate_elem, "axis");
|
||||
|
||||
float dx = skeleton.RequireFloatAttribute(translate_elem, "x");
|
||||
|
|
|
@ -289,22 +289,22 @@ void StdMeshMaterialPass::Load(StdMeshMaterialParserCtx& ctx)
|
|||
}
|
||||
else if(token_name == "specular")
|
||||
{
|
||||
Diffuse[0] = ctx.AdvanceFloat();
|
||||
Diffuse[1] = ctx.AdvanceFloat();
|
||||
Diffuse[2] = ctx.AdvanceFloat();
|
||||
Specular[0] = ctx.AdvanceFloat();
|
||||
Specular[1] = ctx.AdvanceFloat();
|
||||
Specular[2] = ctx.AdvanceFloat();
|
||||
|
||||
// The fourth argument is optional, not the fifth:
|
||||
float diffuse3 = ctx.AdvanceFloat();
|
||||
float specular3 = ctx.AdvanceFloat();
|
||||
|
||||
float shininess;
|
||||
if(ctx.AdvanceFloatOptional(shininess))
|
||||
{
|
||||
Diffuse[3] = diffuse3;
|
||||
Specular[3] = specular3;
|
||||
Shininess = shininess;
|
||||
}
|
||||
else
|
||||
{
|
||||
Shininess = diffuse3;
|
||||
Shininess = specular3;
|
||||
}
|
||||
}
|
||||
else if(token_name == "emissive")
|
||||
|
@ -373,13 +373,18 @@ void StdMeshMaterial::Load(StdMeshMaterialParserCtx& ctx)
|
|||
ctx.Error(StdStrBuf("'") + token_name.getData() + "' unexpected");
|
||||
}
|
||||
|
||||
void StdMeshMatManager::Clear()
|
||||
{
|
||||
Materials.clear();
|
||||
}
|
||||
|
||||
void StdMeshMatManager::Parse(const char* mat_script, const char* filename, StdMeshMaterialTextureLoader& tex_loader)
|
||||
{
|
||||
StdMeshMaterialParserCtx ctx(mat_script, filename, tex_loader);
|
||||
|
||||
Token token;
|
||||
StdStrBuf token_name;
|
||||
while((token = ctx.AdvanceNonEOF(token_name)) == TOKEN_IDTF)
|
||||
while((token = ctx.Advance(token_name)) == TOKEN_IDTF)
|
||||
{
|
||||
if(token_name == "material")
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue