本文整理汇总了C++中MeshObject::loadFromFile方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshObject::loadFromFile方法的具体用法?C++ MeshObject::loadFromFile怎么用?C++ MeshObject::loadFromFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshObject
的用法示例。
在下文中一共展示了MeshObject::loadFromFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readMeshs
void XmlParser::readMeshs(Renderer * renderer ,Scene * scene, XmlNode * meshNode) {
// Read mesh
while(meshNode) {
// Create cube
glm::mat4 id;
MeshObject * mesh = new MeshObject(id);
// Read shaders and init it
int basicShader = renderer->getDefaultBasicShader();
int lightShader = renderer->getDefaultLightShader();
XmlNode * basicShaderNode = meshNode->first_node("basic-shader");
XmlNode * lightShaderNode = meshNode->first_node("light-shader");
// If there is a basic shader node
if (basicShaderNode) {
XmlAttr * vert, * frag;
xmlAttribute(vert, basicShaderNode);
xmlAttribute(frag, basicShaderNode);
// Create new shader
basicShader = renderer->createShaderProg(vert->value(), frag->value());
}
// If there is a light shader node
if (lightShaderNode) {
XmlAttr * vert, * frag;
xmlAttribute(vert, lightShaderNode);
xmlAttribute(frag, lightShaderNode);
// Create new shader
lightShader = renderer->createShaderProg(vert->value(), frag->value());
}
// Init mesh
mesh->init(basicShader, lightShader);
// Load file (it must exist)
XmlAttr * file;
xmlAttribute(file, meshNode);
mesh->loadFromFile(file->value());
// Try to read model
readModel(mesh, meshNode->first_node("model"));
// Add c to scene
scene->addGameObject(mesh);
// Set texture
XmlNode * textureNode = meshNode->first_node("texture");
if (textureNode) {
// Get file name
XmlAttr * file;
xmlAttribute(file, textureNode);
// Create texture
Texture texture(GL_TEXTURE0, std::string(file->value()));
// Set texture
mesh->setTexture(texture);
}
// Set normal map
XmlNode * normalMapNode = meshNode->first_node("normal-map");
if (normalMapNode) {
// Get file name
XmlAttr * file;
xmlAttribute(file, normalMapNode);
// Create texture
Texture normalMap(GL_TEXTURE2, std::string(file->value()));
// Set texture
mesh->setNormalMap(normalMap);
}
// Set material
XmlNode * material = meshNode->first_node("material");
if (material) {
// Create material
Material * m = new Material();
// Set emissive
XmlNode * emissive = material->first_node("emissive");
if (emissive) {
XmlAttr * r, *g, *b;
xmlAttribute(r, emissive);
xmlAttribute(g, emissive);
xmlAttribute(b, emissive);
// Set diffuse
m->setEmissive(atof(r->value()), atof(g->value()),
atof(b->value()));
}
// Read ambient
XmlNode * ambient = material->first_node("ambient");
if (ambient) {
XmlAttr * r, *g, *b;
xmlAttribute(r, ambient);
xmlAttribute(g, ambient);
xmlAttribute(b, ambient);
// Set diffuse
m->setAmbient(atof(r->value()), atof(g->value()),
atof(b->value()));
//.........这里部分代码省略.........