int OgreNodeHandler::startSphere(const X3DAttributes &attr) { std::cout << "Start Sphere\n"; int index = attr.getAttributeIndex(ID::radius); float radius = index == -1 ? 1.0 : attr.getSFFloat(index); const string name = createUniqueName(attr, "sphere"); GeomUtils::createSphere(name , radius, 20, 20, true, false); _currentMesh = MeshManager::getSingleton().getByName(name); _currentEntity = _sceneManager->createEntity(_shapeName, name); return 1; }
int OgreNodeHandler::startDirectionalLight(const X3DAttributes &attr) { Light* light = _sceneManager->createLight(createUniqueName(attr, "directionalLight")); light->setType(Ogre::Light::LT_DIRECTIONAL); // Get the X3D values; SFVec3f direction; SFColor color; int index = attr.getAttributeIndex(ID::direction); if (index != -1) { direction = attr.getSFVec3f(index); } else direction.z = -1; index = attr.getAttributeIndex(ID::color); if (index != -1) { color = attr.getSFColor(index); } else color.r = color.g = color.b = 1; index = attr.getAttributeIndex(ID::intensity); float intensity = (index == -1) ? 1 : attr.getSFFloat(index); index = attr.getAttributeIndex(ID::on); bool on = (index == -1) ? true : attr.getSFBool(index); // Set the Ogre values light->setDirection(direction.x, direction.y, direction.z); Ogre::ColourValue colourValue(color.r, color.g, color.b); colourValue *= intensity; light->setDiffuseColour(colourValue); light->setSpecularColour(colourValue); light->setVisible(on); _nodeStack.top()->attachObject(light); return 1; }
virtual int startMaterial(const X3DAttributes& attr) { testEvent(11, "start Material"); int index = attr.getAttributeIndex(ID::diffuseColor); assert(index != -1); SFColor diffuseColor; attr.getSFColor(index, diffuseColor); assert(diffuseColor.r == 1.0); assert(diffuseColor.g == 0.0); assert(diffuseColor.b == 0.0); cout << "Diffuse Color is: " << diffuseColor.r << " " << diffuseColor.g << " " << diffuseColor.b << endl; index = attr.getAttributeIndex(ID::transparency); assert(index != -1); float transparency = attr.getSFFloat(index); assert(transparency == 0.1f); return CONTINUE; }
int OgreNodeHandler::startMaterial(const X3DAttributes &attr) { std::cout << "Start Material" << std::endl; if (!_currentMaterial.isNull()) { Pass* pass = _currentMaterial->getTechnique(0)->getPass(0); int index = attr.getAttributeIndex(ID::ambientIntensity); float ambientIntensity = (index == -1) ? 0.2f : attr.getSFFloat(index); index = attr.getAttributeIndex(ID::transparency); float transparency = (index == -1) ? 0.0f : attr.getSFFloat(index); SFColor diffuseColor; index = attr.getAttributeIndex(ID::diffuseColor); if (index != -1) { diffuseColor = attr.getSFColor(index); } else { diffuseColor.r = diffuseColor.g = diffuseColor.b = 0.8; } SFColor specularColor; index = attr.getAttributeIndex(ID::specularColor); if (index != -1) { specularColor = attr.getSFColor(index); } SFColor emissiveColor; index = attr.getAttributeIndex(ID::emissiveColor); if (index != -1) { emissiveColor = attr.getSFColor(index); } index = attr.getAttributeIndex(ID::shininess); float shininess = (index == -1) ? 0.2f : attr.getSFFloat(index); shininess = Math::Clamp(shininess * 128.0f, 0.0f, 128.0f); pass->setAmbient(ambientIntensity * diffuseColor.r, ambientIntensity * diffuseColor.g, ambientIntensity * diffuseColor.b); pass->setDiffuse(diffuseColor.r, diffuseColor.g, diffuseColor.b, 1.0f - transparency); pass->setSpecular(specularColor.r, specularColor.g, specularColor.b, 1.0f - transparency); pass->setSelfIllumination(emissiveColor.r, emissiveColor.g, emissiveColor.b); pass->setShininess( shininess ); pass->setLightingEnabled(true); } return 1; }