OSGMaterialStruct::OSGMaterialStruct(const mars::interfaces::MaterialData &mat) { setColorMode(osg::Material::OFF); setAmbient(osg::Material::FRONT, toOSGVec4(mat.ambientFront)); setAmbient(osg::Material::BACK, toOSGVec4(mat.ambientBack)); setSpecular(osg::Material::FRONT, toOSGVec4(mat.specularFront)); setSpecular(osg::Material::BACK, toOSGVec4(mat.specularBack)); setDiffuse(osg::Material::FRONT, toOSGVec4(mat.diffuseFront)); setDiffuse(osg::Material::BACK, toOSGVec4(mat.diffuseBack)); setEmission(osg::Material::FRONT, toOSGVec4(mat.emissionFront)); setEmission(osg::Material::BACK, toOSGVec4(mat.emissionBack)); setShininess(osg::Material::FRONT_AND_BACK, mat.shininess); setTransparency(osg::Material::FRONT_AND_BACK, mat.transparency); }
Light::Light(LIGHT_TYPE type) { lights.push_back(this); if(availableLights.size() > 0) { lightNum = availableLights[0]; availableLights.erase(availableLights.begin()); Visible(true); setLightType(type); setPosition(0, 0, 0); setCutoff(45); setExponent(12); setSpotDirection(0, -1, 0); setAmbient(0, 0, 0, 1); setDiffuse(1, 1, 1, 1); setSpecular(1, 1, 1, 1); updateLight(); } else { lightNum = 0; Visible(false); } }
void Lights::create(GLuint lightNum, const Color &ambient, const Color &diffuse, const Vector4f &position) { // the light being defined _lightNumber = lightNum; setAmbient(ambient); setDiffuse(diffuse); setPosition(position); }
Material::Material() { setAmbient(0.2f, 0.2f, 0.2f, 1.0f); setDiffuse(0.8f, 0.8f, 0.8f, 1.0f); setSpecular(0, 0, 0, 1); setEmission(0, 0, 0, 1); shininess = 0; }
LightSource::LightSource(GLenum number) { _num = number; setPosition(0,0,1.0,1.0); //setDirection(Vector3(0,0,1)); setAmbient(0.0, 0.0, 0.0, 1.0); setDiffuse(1.0, 1.0, 1.0, 1.0); setSpecular(1.0, 1.0, 1.0, 1.0); setState(true); setExponent(0); setCutOff(180); }
Light::Light(bool dynamic_in) : shadowmapTex(0), coneTex(0), has_target(false), has_shadow(false), parent(NULL), has_projector(false), glLightId(0), nearclip(1.0f), farclip(200.0f), sceneObjTarget(NULL) { setType(LIGHT_POINT); setAmbient(RGB(0.0f,0.0f,0.0f)); setDiffuse(RGB(1.0f,1.0f,1.0f)); setSpecular(RGB(0.0f,0.0f,0.0f)); setConstantAttenuation(0.4f); setLinearAttenuation(0.01f); setQuadraticAttenuation(0.001f); dynamic = dynamic_in; }
iNodeLight::iNodeLight(iNodeLight* node) : iNode() { con_assert(node != nullptr, "zero pointer"); _nodeType = node->_nodeType; _nodeKind = node->_nodeKind; setName(node->getName()); setAmbient(node->getAmbient()); setDiffuse(node->getDiffuse()); setSpecular(node->getSpecular()); setType(node->getType()); }
CGFlight::CGFlight(unsigned int lightid, float* pos, float *dir) { try { id = lightid; position[0] = pos[0]; position[1] = pos[1]; position[2] = pos[2]; position[3] = pos[3]; material = CGFlight::default_light_material; if (dir == NULL) { direction[0] = 0; direction[1] = -1; direction[2] = 0; } else { direction[0] = dir[0]; direction[1] = dir[1]; direction[2] = dir[2]; } float __tmp_1[4] = {CG_GLIGHT_DEFAULT_AMBIENT}; setAmbient(__tmp_1); float __tmp_2[4] = {CG_GLIGHT_DEFAULT_DIFFUSE}; setDiffuse(__tmp_2); float __tmp_3[4] = {CG_GLIGHT_DEFAULT_SPECULAR}; setSpecular(__tmp_3); setKc(CG_GLIGHT_DEFAULT_KC); setKl(CG_GLIGHT_DEFAULT_KL); setKq(CG_GLIGHT_DEFAULT_KQ); update(); } catch (std::exception&) { throw GLexception("CGFlight::constructor failed"); } glu_quadric = gluNewQuadric(); gluQuadricOrientation(glu_quadric, GLU_INSIDE); }
void ViewLightGL::lightEvent(ViewEvent * event) { if (event->type() == ViewEvent::eLightSet) { ViewLightSetEvent * e = (ViewLightSetEvent *)event; switch(e->def){ case ViewLightSetEvent::ePosition: setPosition(e->position); break; case ViewLightSetEvent::eActivation: setEnabled(e->activation); break; case ViewLightSetEvent::eAmbient: setAmbient(e->ambient); break; case ViewLightSetEvent::eDiffuse: setDiffuse(e->diffuse); break; case ViewLightSetEvent::eSpecular: setSpecular(e->specular); break; } } else if (event->type() == ViewEvent::eLightGet){ ViewLightGetEvent * e = (ViewLightGetEvent *)event; switch(e->def){ case ViewLightSetEvent::ePosition: *e->position = getPosition(); break; case ViewLightSetEvent::eActivation: *e->activation = isEnabled(); break; case ViewLightSetEvent::eAmbient: *e->ambient = __ambient; break; case ViewLightSetEvent::eDiffuse: *e->diffuse = __diffuse; break; case ViewLightSetEvent::eSpecular: *e->specular = __specular; break; } } }
LightSource::LightSource( GLfloat arg1, GLfloat arg2, GLfloat arg3 ) { for( int i = 0; i < GL_MAX_LIGHTS; i++ ) if( lights_used[ i ] == false ) { lights_used[ i ] = true; light_numb = GL_LIGHT0;//;translate( i ); break; } /* Light is not attached to anything initially */ mass = NULL; setAmbient( 0, 0, 0, 1 ); setDiffuse( arg1, arg2, arg3, 1 ); setIntensity( arg1, arg2, arg3, 1 ); enable(); }
OpenGLScene::OpenGLScene() : m_rootNode(new SceneNode("__root__")) { m_cameraNode=std::make_shared<SceneNode>("camera"); m_rootNode->addChild(m_cameraNode); auto camera=std::make_shared<Camera>(m_cameraNode); m_cameraNode->setCamera(camera); m_lightNode=std::make_shared<SceneNode>("light"); m_rootNode->addChild(m_lightNode); m_lightNode->setPosition(1.0f, 2.0f, 3.0f); auto light=std::make_shared<Light>(); light->setDiffuse(Vec3(1.0f, 0.8f, 0.8f)); m_lightNode->setLight(light); auto meshNode=std::make_shared<SceneNode>("triangle"); auto mesh=IndexedVertexBuffer::CreateTriangle(); meshNode->setMesh(mesh); m_rootNode->addChild(meshNode); }
Light::Light(float r, float g, float b, float a) { handle = lightNumber++; ZeroMemory( &light, sizeof(light) ); setType(D3DLIGHT_POINT); setDiffuse(r, g, b, a); setAmbient(0, 0, 0, 0); setRange((float)sqrt(FLT_MAX)); setSpecular(r, g, b, a); setAttenuation(1, 0, 0); uniSetLightInfo(handle, light); size = 1; int color = ((int)(r * 255) << 16) | ((int)(g * 255) << 8) | ((int)b * 255) | 0xff000000; calc = true; draw = false; // this->sprite = new Sprite(0.6f, color, "lens02"); }
Light *Light::loadFromFile(const string &filePath) { ptree tree_handle = defaultLoader(filePath); string argName; vector<string> parseStorage; float storage[4]; memset(storage, 0, sizeof(float)*4); argName = tree_handle.get<string>("type_settings.diffuse", "1, 1, 1, 1"); if (parseArguments("diffuse", argName, storage, parseStorage)) setDiffuse(colour(storage[0], storage[1], storage[2], storage[3])); argName = tree_handle.get<string>("type_settings.specular", "0, 0, 0, 1"); if (parseArguments("specular", argName, storage, parseStorage)) setSpecular(colour(storage[0], storage[1], storage[2], storage[3])); setRadius(tree_handle.get<float>("type_settings.radius", 100000)); setPower(tree_handle.get<float>("type_settings.power", 1)); showDebug(false); return this; }
void SphereReflectionTest::run() { auto box = SceneTest::addObject(new Object()); box->scale.setAll(4.0); box->scale.z = 6.0; box->translate.z = -0.0; auto material1 = std::make_shared<SimpleMaterial>(); material1->setAmbient(0.0, 0.0, 0.4); material1->setDiffuse(0.0, 0.0, 0.4); //material1->reflectivity = 0.3; auto square1 = std::make_shared<Object>(); box->addObject(square1); square1->geometry = std::make_shared<SquareGeometry>(); square1->material = material1; square1->rotate.y = 90 * PI / 180; square1->translate.x = -0.5; auto material2 = std::make_shared<SimpleMaterial>(); material2->setAmbient(0.4, 0.0, 0.0); material2->setDiffuse(0.4, 0.4, 0.4); //material2->reflectivity = 0.3; auto square2 = std::make_shared<Object>(); box->addObject(square2); square2->geometry = std::make_shared<SquareGeometry>(); square2->material = material2; square2->rotate.y = -90 * PI / 180; square2->translate.x = 0.5; auto material6 = std::make_shared<SimpleMaterial>(); material6->setAmbient(0.0, 0.4, 0.0); material6->setDiffuse(0.4, 0.4, 0.4); auto material7 = std::make_shared<SimpleMaterial>(); material7->setAmbient(0.4, 0.4, 0.4); material7->setDiffuse(0.4, 0.4, 0.4); auto material3 = std::make_shared<SimpleMaterial>(); material3->setAmbient(0.3, 0.3, 0.3); material3->setDiffuse(0.4, 0.4, 0.4); material3->setSpecular(0.2, 0.2, 0.0); //material3->reflects = true; //material3->reflectivity = 0.4; auto square3 = std::make_shared<Object>(); box->addObject(square3); square3->geometry = std::make_shared<SquareGeometry>(); square3->material = material3; square3->translate.z = -0.5; auto square4 = std::make_shared<Object>(); box->addObject(square4); square4->geometry = std::make_shared<SquareGeometry>(); square4->material = material7; square4->rotate.x = 90 * PI / 180; square4->translate.y = 0.5; auto square5 = std::make_shared<Object>(); box->addObject(square5); square5->geometry = std::make_shared<SquareGeometry>(); square5->material = material6; square5->rotate.x = -90 * PI / 180; square5->translate.y = -0.5; /* auto square6 = std::make_shared<Object>(); box->addObject(square6); square6->geometry = std::make_shared<SquareGeometry>(); square6->material = material3; square6->translate.z = 0.5; */ auto material4 = std::make_shared<SimpleMaterial>(); //material4->setDiffuse(0.3, 0.3, 0.3); //material4->setSpecular(0.2, 0.2, 0.2); //material4->reflectivity = 0.35; //material4->refractivity = 0.6; material4->reflects = true; material4->refractiveIndex = 1.75; // auto sphere1 = SceneTest::addObject(new Object()); // sphere1->geometry = std::make_shared<SphereGeometry>(); // sphere1->material = material4; // sphere1->scale.setAll(0.33); // sphere1->translate.y = -1.5; auto teapot = SceneTest::addObjectFromFile("/Users/zhaoyuhan/Documents/smooth_teapot.obj"); teapot->material = material4; //teapot->scale.setAll(0.20); teapot->translate.y = -1.5; teapot->translate.z = -1.0; auto material5 = std::make_shared<SimpleMaterial>(); material5->reflects = true; material5->refractiveIndex = 1.75; //material5->reflectivity = 0.35; auto sphere2 = SceneTest::addObject(new Object()); sphere2->geometry = std::make_shared<SphereGeometry>(); sphere2->material = material5; sphere2->scale.setAll(0.15); sphere2->translate.x = 0.5; sphere2->translate.y = -1.0; // auto teapot = SceneTest::addObjectFromFile("/Users/zhaoyuhan/Documents/smooth_teapot.obj"); // teapot->material = material4; // teapot->scale.setAll(0.2); // teapot->translate.x = 0.8; // teapot->translate.y = -1.0; //auto sphere1 = SceneTest::addObjectFromFile("/Users/zhaoyuhan/Documents/sphere.obj"); //sphere1->material = material4; auto light1 = SceneTest::addLight(new BlinnLight()); light1->location.set(0.0, 0.0, 4.0); light1->lightColor.set(0.8, 0.8, 0.8); auto light2 = std::make_shared<BlinnLight>(); light2->lightColor.set(0.5, 0.5, 0.0); square4->addObject(light2); this->scene->lights.push_back(light2); this->camera->location = {0.0, -1.0, 2.0}; this->camera->focalLength = 2.0; SceneTest::run(); }
//----------------------------------------------------------------------- void Technique::setDiffuse(const ColourValue& diffuse) { setDiffuse(diffuse.r, diffuse.g, diffuse.b, diffuse.a); }
void loadVtk(string path, VRTransformPtr res) { cout << "load VTK file " << path << endl; VRGeoData geo; vtkDataSetReader* reader = vtkDataSetReader::New(); reader->SetFileName(path.c_str()); reader->ReadAllScalarsOn(); reader->ReadAllVectorsOn(); reader->ReadAllNormalsOn(); reader->ReadAllTensorsOn(); reader->ReadAllTCoordsOn(); reader->ReadAllFieldsOn(); reader->ReadAllColorScalarsOn(); reader->Update(); vtkDataSet* dataset = reader->GetOutput(); int npoints = dataset->GetNumberOfPoints(); int ncells = dataset->GetNumberOfCells(); int nscalars = reader->GetNumberOfScalarsInFile(); int nvectors = reader->GetNumberOfVectorsInFile(); int ntensors = reader->GetNumberOfTensorsInFile(); cout << "dataset sizes: " << npoints << " " << ncells << " " << nscalars << " " << nvectors << " " << ntensors << endl; for (int i=0; i<npoints; i++) { auto p = dataset->GetPoint(i); Vec3d v(p[0], p[1], p[2]); geo.pushVert(v); cout << "point " << v << endl; } auto getCellPIDs = [](vtkCell* c) { vector<int> res; auto ids = c->GetPointIds(); for (int k=0; k<ids->GetNumberOfIds(); k++) { res.push_back( ids->GetId(k) ); } return res; }; for (int i=0; i<ncells; i++) { vtkCell* c = dataset->GetCell(i); //int d = c->GetCellDimension(); //int t = c->GetCellType(); string type = c->GetClassName(); cout << "cell type " << type << endl; if (type == "vtkQuad") { auto j = getCellPIDs(c); geo.pushQuad(j[0], j[1], j[2], j[3]); } } //vtkCellData* cells = dataset->GetCellData(); vtkPointData* points = dataset->GetPointData(); cout << "POINT_DATA:\n"; if (points) { std::cout << " contains point data with " << points->GetNumberOfArrays() << " arrays." << std::endl; for (int i = 0; i < points->GetNumberOfArrays(); i++) { std::cout << "\tArray " << i << " is named " << (points->GetArrayName(i) ? points->GetArrayName(i) : "NULL") << std::endl; } for(int i=0; vtkDataArray* a = points->GetArray(i); i++ ) { int size = a->GetNumberOfTuples(); int comp = a->GetNumberOfComponents(); cout << " data array " << size << " " << comp << endl; for (int j=0; j<size; j++) { cout << "pnt:"; for (int k=0; k<comp; k++) cout << " " << a->GetComponent(j, k); cout << endl; } } } cout << "FIELD_DATA:\n"; if (dataset->GetFieldData()) { std::cout << " contains field data with " << dataset->GetFieldData()->GetNumberOfArrays() << " arrays." << std::endl; for (int i = 0; i < dataset->GetFieldData()->GetNumberOfArrays(); i++) { std::cout << "\tArray " << i << " is named " << dataset->GetFieldData()->GetArray(i)->GetName() << std::endl; } } cout << "CELL_DATA:\n"; vtkCellData *cd = dataset->GetCellData(); if (cd) { std::cout << " contains cell data with " << cd->GetNumberOfArrays() << " arrays." << std::endl; for (int i = 0; i < cd->GetNumberOfArrays(); i++) { std::cout << "\tArray " << i << " is named " << (cd->GetArrayName(i) ? cd->GetArrayName(i) : "NULL") << std::endl; } } /*if (cells) { for(int i=0; vtkDataArray* a = points->GetArray(i); i++ ) { int size = a->GetNumberOfTuples(); int comp = a->GetNumberOfComponents(); for (int j=0; j<size; j++) { cout << "cell:"; for (int k=0; k<comp; k++) cout << " " << a->GetComponent(j, k); cout << endl; } } }*/ string name = "vtk"; auto m = VRMaterial::create(name + "_mat"); m->setLit(0); m->setDiffuse(Color3f(0.3,0.7,1.0)); VRGeometryPtr g = geo.asGeometry(name); g->setMaterial(m); //g->updateNormals(); res->addChild( g ); }
int main(int argc, char** argv) { osg::ArgumentParser arguments( &argc, argv ); std::string dbPath; arguments.read("--db_path", dbPath); std::srand ( unsigned ( std::time(0) ) ); auto board = Board(boardDefinition, boardSizeX, boardSizeY, dbPath); auto ghostFactory = GhostFactory(); auto main_obj = make_ref<osg::Group>(); main_obj->addChild(board.draw().get()); auto ghostModel = osgDB::readNodeFile(dbPath + "/cow.osg"); auto ghostCount = 16; while(ghostCount--) { main_obj->addChild(ghostFactory.drawGhost(board, ghostModel).get()); } // init rotate auto init_rotate = make_ref<osg::MatrixTransform>(); init_rotate->setMatrix( osg::Matrix::rotate(osg::PI * 2, osg::Vec3(1.0f, 0.0f, 0.0f)) ); // chain rotates init_rotate->addChild(main_obj); // Root group auto root = make_ref<osg::Group>(); root->addChild(init_rotate); // Setup fog if(FogEnabled) { osg::ref_ptr<osg::Fog> fog = new osg::Fog; fog->setMode( osg::Fog::EXP2 ); fog->setStart( 0.0f ); fog->setEnd(board.getFieldSizeX() * 20); fog->setDensity(0.0135); fog->setColor( osg::Vec4(0., 0., 0., 1.0) ); root->getOrCreateStateSet()->setAttributeAndModes(fog.get()); } // Start viewer osgViewer::Viewer viewer; // Set up flashlight auto lightSource = make_ref<osg::LightSource>(); lightSource->setReferenceFrame(osg::LightSource::ABSOLUTE_RF); auto light = lightSource->getLight(); const osg::Vec3 lightPosition{1.5, -1, -1}; // right, down, front light->setPosition(osg::Vec4{lightPosition, 1}); light->setDirection(osg::Vec3{0, 0, -1} * 30 - lightPosition); light->setSpotExponent(60); light->setSpotCutoff(90); light->setDiffuse(osg::Vec4(1, 1, 1, 1)); light->setAmbient(osg::Vec4(0.6, 0.6, 0.6, 1)); light->setSpecular(osg::Vec4(1, 1, 1, 1)); light->setLinearAttenuation(0.001); light->setConstantAttenuation(0.5); root->addChild(lightSource); double height = std::min(board.getFieldSizeX(), board.getFieldSizeY()) / 1.5; auto fpsManipulator = make_ref<FPSManipulator>(board, viewer, *light); fpsManipulator->setHomePosition( osg::Vec3d(board.getFieldCenterX(1), board.getFieldCenterY(10), height), osg::Vec3d(0.0f, 0.0f, height), osg::Vec3d(0.0f, 0.0f, 1.0f) ); auto keySwitch = make_ref<osgGA::KeySwitchMatrixManipulator>(); keySwitch->addNumberedMatrixManipulator(make_ref<osgGA::OrbitManipulator>()); keySwitch->addNumberedMatrixManipulator(fpsManipulator); viewer.setCameraManipulator(keySwitch); viewer.home(); viewer.setSceneData( root ); osgViewer::Viewer::Windows windows; viewer.getWindows(windows); viewer.getCamera()->setClearColor(osg::Vec4{0, 0, 0, 0}); viewer.getCamera()->getView()->setLightingMode(osg::View::HEADLIGHT); auto defaultLight = viewer.getCamera()->getView()->getLight(); defaultLight->setDiffuse(osg::Vec4(0, 0, 0, 1)); defaultLight->setAmbient(osg::Vec4(0, 0, 0, 1)); defaultLight->setSpecular(osg::Vec4(0, 0, 0, 1)); // Shaders auto program = make_ref<osg::Program>(); auto fragmentObject = make_ref<osg::Shader>(osg::Shader::FRAGMENT); loadShaderSource(fragmentObject, dbPath + "/shader.frag"); auto vertexObject = make_ref<osg::Shader>(osg::Shader::VERTEX); loadShaderSource(vertexObject, dbPath + "/shader.vert"); program->addShader(vertexObject); program->addShader(fragmentObject); root->getOrCreateStateSet()->setAttributeAndModes(program, osg::StateAttribute::ON); root->getOrCreateStateSet()->addUniform(new osg::Uniform("samplerName", TEXTURE_UNIT)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("Shininess", BoardObjectsShininess)); root->getOrCreateStateSet()->addUniform(new osg::Uniform("FogEnabled", FogEnabled)); // Optimize osgUtil::Optimizer optimzer; optimzer.optimize(root); viewer.setUpViewOnSingleScreen(0); return viewer.run(); }
// *************************************************************************** void CMaterial::serial(NLMISC::IStream &f) { /* *********************************************** * WARNING: This Class/Method must be thread-safe (ctor/dtor/serial): no static access for instance * It can be loaded/called through CAsyncFileManager for instance * ***********************************************/ /* Version 9: - Added support for third operand (for Mad operator) Version 8: - Serial _TexCoordGenMode Version 7: - Lightmap color and Mulx2 Version 6: - Texture matrix animation Version 5: - AlphaTest threshold Version 4: - Texture Addressing modes Version 3: - LightMaps. Version 2: - Shininess. Version 1: - texture environement. Version 0: - base version. */ sint ver= f.serialVersion(9); // For the version <=1: nlassert(IDRV_MAT_MAXTEXTURES==4); f.serialEnum(_ShaderType); f.serial(_Flags); f.serialEnum(_SrcBlend); f.serialEnum(_DstBlend); f.serialEnum(_ZFunction); f.serial(_ZBias); f.serial(_Color); f.serial(_Emissive, _Ambient, _Diffuse, _Specular); if(ver>=2) { f.serial(_Shininess); } if(ver>=5) { f.serial(_AlphaTestThreshold); } if(ver>=8) { f.serial(_TexCoordGenMode); } else _TexCoordGenMode = 0; for(uint32 i=0;i<IDRV_MAT_MAXTEXTURES;i++) { // Serial texture descriptor. _Textures[i].serialPolyPtr(f); // Read texture environnement, or setup them. if(ver>=1) { _TexEnvs[i].serial(f, ver >= 9 ? 1 : 0); } else { // Else setup as default behavior, like before... if(f.isReading()) _TexEnvs[i].setDefault(); } } if(ver>=3) { if(ver>=7) { uint32 n; if (f.isReading()) { f.serial(n); _LightMaps.resize(n); } else { n = (uint32)_LightMaps.size(); f.serial(n); } for (uint32 i = 0; i < n; ++i) _LightMaps[i].serial2(f); f.serial(_LightMapsMulx2); } else { f.serialCont(_LightMaps); } } if (ver >= 4) { if (_Flags & IDRV_MAT_TEX_ADDR) { for(uint32 i=0;i<IDRV_MAT_MAXTEXTURES;i++) { f.serial(_TexAddrMode[i]); } } } if(f.isReading()) { // Converte Deprecated DEFMAT to std Mat. if(_Flags & IDRV_MAT_DEFMAT) { setEmissive(CRGBA::Black); setAmbient(CRGBA::White); setDiffuse(CRGBA::White); setSpecular(CRGBA::Black); } // All states of material are modified. _Touched= IDRV_TOUCHED_ALL; if ((_Flags & IDRV_MAT_USER_TEX_MAT_ALL)) // are there user textrue coordinates matrix ? { std::auto_ptr<CUserTexMat> newPtr(new CUserTexMat); // create new //std::swap(_TexUserMat, newPtr); // replace old _TexUserMat = newPtr; } } if (ver >= 6) { for(uint i=0; i < IDRV_MAT_MAXTEXTURES; ++i) { if (isUserTexMatEnabled(i)) { f.serial(_TexUserMat->TexMat[i]); } } } }
void loadVtk_old(string path, VRTransformPtr res) { cout << "load VTK file " << path << endl; ifstream file(path.c_str()); string line; auto next = [&]() -> string& { getline(file, line); return line; }; VTKProject project; project.version = splitString( next() )[4]; project.title = next(); project.format = next(); project.dataset = splitString( next() )[1]; VRGeoData geo; // build geometry if (project.dataset == "STRUCTURED_POINTS") { auto r = splitString( next() ); Vec3i dims = toValue<Vec3i>( r[1] + " " + r[2] + " " + r[3] ); r = splitString( next() ); Vec3d p0 = toValue<Vec3d>( r[1] + " " + r[2] + " " + r[3] ); r = splitString( next() ); Vec3d d = toValue<Vec3d>( r[1] + " " + r[2] + " " + r[3] ); for (int k=0; k<dims[2]; k++) { for (int j=0; j<dims[1]; j++) { for (int i=0; i<dims[0]; i++) { geo.pushVert(p0 + Vec3d(d[0]*i, d[1]*j, d[2]*k) ); geo.pushPoint(); } } } } if (project.dataset == "STRUCTURED_GRID") { auto r = splitString( next() ); Vec3i dims = toValue<Vec3i>( r[1] + " " + r[2] + " " + r[3] ); r = splitString( next() ); int N = toInt(r[1]); string type = r[2]; // points vector<Vec3d> points; for (int i=0; i<N; i++) { Vec3d p = toValue<Vec3d>( next() ); points.push_back(p); geo.pushVert(p); geo.pushPoint(); } } if (project.dataset == "RECTILINEAR_GRID") { ; } if (project.dataset == "UNSTRUCTURED_GRID") { ; } if (project.dataset == "POLYDATA") { auto r = splitString( next() ); int N = toInt(r[1]); string type = r[2]; // points for (int i=0; i<N; i++) geo.pushVert( toValue<Vec3d>( next() ) ); while (next() != "") { r = splitString( line ); string type = r[0]; N = toInt(r[1]); //int size = toInt(r[2]); for (int i=0; i<N; i++) { // for each primitive r = splitString( next() ); int Ni = toInt(r[0]); // length of primitive cout << line << " " << Ni << endl; //if (Ni == 2) geo.pushLine(toInt(r[1]), toInt(r[2])); if (Ni == 3) geo.pushTri(toInt(r[1]), toInt(r[2]), toInt(r[3])); if (Ni == 4) geo.pushQuad(toInt(r[1]), toInt(r[2]), toInt(r[3]), toInt(r[4])); } } } if (project.dataset == "FIELD") { ; } // parsing finished cout << project.toString() << endl; file.close(); auto m = VRMaterial::create(project.title + "_mat"); m->setLit(0); m->setDiffuse(Color3f(0.3,0.7,1.0)); VRGeometryPtr g = geo.asGeometry(project.title); g->setMaterial(m); //g->updateNormals(); res->addChild( g ); }
//----------------------------------------------------------------------- void Material::setDiffuse(const ColourValue& diffuse) { setDiffuse(diffuse.r, diffuse.g, diffuse.b, diffuse.a); }
void Material::setDiffuse(float r, float g, float b, float a) { setDiffuse(glm::vec4(r, g, b, a)); }
void Light::init() { setAmbient(getComponents()->getAmbient()); setDiffuse(getComponents()->getDiffuse()); setSpecular(getComponents()->getSpecular()); }
void Material::setDiffuse(const Color &color) { auto ptr = lock(); if ( ptr ) ptr->setDiffuse(color); }
void PMFinish::restoreMemento( PMMemento* s ) { PMMementoDataIterator it( s ); PMMementoData* data; for( ; it.current( ); ++it ) { data = it.current( ); if( data->objectType( ) == s_pMetaObject ) { switch( data->valueID( ) ) { case PMAmbientColorID: setAmbientColor( data->colorData( ) ); break; case PMDiffuseID: setDiffuse( data->doubleData( ) ); break; case PMBrillianceID: setBrilliance( data->doubleData( ) ); break; case PMCrandID: setCrand( data->doubleData( ) ); break; case PMConserveEnergyID: setConserveEnergy( data->boolData( ) ); case PMPhongID: setPhong( data->doubleData( ) ); break; case PMPhongSizeID: setPhongSize( data->doubleData( ) ); break; case PMMetallicID: setMetallic( data->doubleData( ) ); break; case PMSpecularID: setSpecular( data->doubleData( ) ); break; case PMRoughnessID: setRoughness( data->doubleData( ) ); break; case PMIridID: setIrid( data->boolData( ) ); break; case PMIridAmountID: setIridAmount( data->doubleData( ) ); break; case PMIridThicknessID: setIridThickness( data->doubleData( ) ); break; case PMIridTurbulenceID: setIridTurbulence( data->doubleData( ) ); break; case PMReflectionColorID: setReflectionColor( data->colorData( ) ); break; case PMReflectionMinColorID: setReflectionMinColor( data->colorData( ) ); break; case PMReflectionFresnelID: setReflectionFresnel( data->boolData( ) ); break; case PMReflectionFalloffID: setReflectionFalloff( data->doubleData( ) ); break; case PMReflectionExponentID: setReflectionExponent( data->doubleData( ) ); break; case PMReflectionMetallicID: setReflectionMetallic( data->doubleData( ) ); break; case PMEnableAmbientID: enableAmbient( data->boolData( ) ); break; case PMEnablePhongID: enablePhong( data->boolData( ) ); break; case PMEnablePhongSizeID: enablePhongSize( data->boolData( ) ); break; case PMEnableDiffuseID: enableDiffuse( data->boolData( ) ); break; case PMEnableBrillianceID: enableBrilliance( data->boolData( ) ); break; case PMEnableCrandID: enableCrand( data->boolData( ) ); break; case PMEnableSpecularID: enableSpecular( data->boolData( ) ); break; case PMEnableRoughnessID: enableRoughness( data->boolData( ) ); break; case PMEnableMetallicID: enableMetallic( data->boolData( ) ); break; case PMEnableReflectionID: enableReflection( data->boolData( ) ); break; case PMEnableReflectionMinID: enableReflectionMin( data->boolData( ) ); break; case PMEnableRefFalloffID: enableRefFalloff( data->boolData( ) ); break; case PMEnableRefExponentID: enableRefExponent( data->boolData( ) ); break; case PMEnableRefMetallicID: enableRefMetallic( data->boolData( ) ); break; default: kdError( PMArea ) << "Wrong ID in PMFinish::restoreMemento\n"; break; } } } Base::restoreMemento( s ); }