bool CloudStation::SetColorPerVertex(osg::Vec4Array& colors) { osg::Group* pc=dynamic_cast<osg::Group*>( this->getChild(1)); if(pc==NULL) return false; osg::Vec4Array::iterator sitr=colors.begin(); osg::Vec4Array::iterator eitr=colors.begin(); for(unsigned int i=0; i<pc->getNumChildren(); i++) { osg::Geode* geode = dynamic_cast<osg::Geode*>(pc->getChild(i)); if(geode==NULL) continue; osg::Array* nv = geode->getDrawable(0)->asGeometry()->getVertexArray(); osg::Vec3Array* v3a = dynamic_cast<osg::Vec3Array*>(nv); if(v3a==NULL) continue; eitr+=v3a->size()-1; osg::Vec4Array* color_sub = new osg::Vec4Array(sitr, eitr); eitr++; sitr=eitr; geode->getDrawable(0)->asGeometry()->setColorArray(color_sub); geode->getDrawable(0)->asGeometry()->setColorBinding(osg::Geometry::BIND_PER_VERTEX); if(eitr==colors.end()) break; } return true; }
void Model::arrangeFaceColors(const osg::Vec4Array &colors) { if (!this->m_mesh || !this->m_colorArray || !this->m_vertexGeometry || !this->m_edgeGeometry || !this->m_faceGeometry) return; if (this->m_usingSharedVertex) return; if (colors.size() != this->m_mesh->fn * 3) return; this->m_colorArray->assign(colors.begin(), colors.end()); this->m_vertexGeometry->dirtyDisplayList(); this->m_edgeGeometry->dirtyDisplayList(); this->m_faceGeometry->dirtyDisplayList(); }
void Model::arrangeVertexColors(const osg::Vec4Array &colors) { if (!this->m_mesh || !this->m_colorArray || !this->m_vertexGeometry || !this->m_edgeGeometry || !this->m_faceGeometry) return; if (colors.size() != this->m_mesh->vn) return; if (this->m_usingSharedVertex) { this->m_colorArray->assign(colors.begin(), colors.end()); } else { this->m_colorArray->clear(); this->m_colorArray->reserve(this->m_mesh->fn * 3); for (pcvcg::TriMesh::ConstFaceIterator cf_iter = this->m_mesh->face.begin(); cf_iter != this->m_mesh->face.end(); ++cf_iter) { this->m_colorArray->push_back(colors[vcg::tri::Index(*this->m_mesh, cf_iter->cV(0))]); this->m_colorArray->push_back(colors[vcg::tri::Index(*this->m_mesh, cf_iter->cV(1))]); this->m_colorArray->push_back(colors[vcg::tri::Index(*this->m_mesh, cf_iter->cV(2))]); } } this->m_vertexGeometry->dirtyDisplayList(); this->m_edgeGeometry->dirtyDisplayList(); this->m_faceGeometry->dirtyDisplayList(); }