| 474 | } |
| 475 | |
| 476 | Ogre::MaterialPtr parseMaterial(const Appearance *app, const String &name) |
| 477 | { |
| 478 | vrmllib::Material *vm = app ? dynamic_cast<vrmllib::Material *>(app->material) : 0; |
| 479 | vrmllib::ImageTexture *texture = app ? dynamic_cast<vrmllib::ImageTexture *>(app->texture) : 0; |
| 480 | |
| 481 | Ogre::MaterialPtr m = MaterialManager::getSingleton().create(name, |
| 482 | ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); |
| 483 | |
| 484 | ColourValue diffuse = texture ? ColourValue::White : col(vm->diffuseColor); |
| 485 | // diffuse colour is unused by VRML when a texture is avaliable, |
| 486 | // set to white to give the same effect in OGRE |
| 487 | |
| 488 | ColourValue a = diffuse; |
| 489 | a.r *= vm->ambientIntensity; |
| 490 | a.g *= vm->ambientIntensity; |
| 491 | a.b *= vm->ambientIntensity; |
| 492 | m->setAmbient(a); |
| 493 | m->setDiffuse(diffuse); |
| 494 | m->setSelfIllumination(col(vm->emissiveColor)); |
| 495 | m->setShininess(vm->shininess); |
| 496 | m->setSpecular(col(vm->specularColor)); |
| 497 | |
| 498 | m->setLightingEnabled(app); |
| 499 | |
| 500 | if (texture && !texture->url.empty()) { |
| 501 | String texName = texture->url.front(); |
| 502 | size_t p = texName.find_last_of("/\\"); |
| 503 | if (p != texName.npos) { |
| 504 | LogManager::getSingleton().logMessage("Stripping path from texture " + texName); |
| 505 | texName.erase(0, p+1); |
| 506 | } |
| 507 | |
| 508 | LogManager::getSingleton().logMessage("Adding texture layer for " + texName); |
| 509 | |
| 510 | Ogre::TextureUnitState *l = m->addTextureLayer(texName); |
| 511 | l->setTextureAddressingMode(texture->repeatS ? |
| 512 | Ogre::TextureUnitState::TAM_WRAP : Ogre::TextureUnitState::TAM_CLAMP); |
| 513 | } |
| 514 | |
| 515 | return m; |
| 516 | } |
| 517 | |
| 518 | Matrix4 transMat(vrmllib::vec3 v, bool inverse) |
| 519 | { |
no test coverage detected