/** Returns the average of all normals of the mesh (not normalized, can be zero) **/ Vec3f VRGeometry::getAverageNormal() { if (!meshSet) return Vec3f(0,1,0); GeoVec3fPropertyRecPtr norms = dynamic_cast<GeoVec3fProperty*>(mesh->getNormals()); Vec3f normal = Vec3f(0,0,0); for (uint i=0;i<norms->size();i++) { normal += Vec3f(norms->getValue(i)); } normal *= 1./norms->size(); return normal; }
void VRGeometry::readSharedMemory(string segment, string object) { VRSharedMemory sm(segment, false); int sm_state = sm.getObject<int>(object+"_state"); while (sm.getObject<int>(object+"_state") == sm_state) { cout << "VRGeometry::readSharedMemory: waiting for data: " << sm_state << endl; sleep(1); } // read buffer auto sm_types = sm.getVector<int>(object+"_types"); auto sm_lengths = sm.getVector<int>(object+"_lengths"); auto sm_pos = sm.getVector<float>(object+"_pos"); auto sm_norms = sm.getVector<float>(object+"_norms"); auto sm_inds = sm.getVector<int>(object+"_inds"); auto sm_cols = sm.getVector<float>(object+"_cols"); GeoPnt3fPropertyRecPtr pos = GeoPnt3fProperty::create(); GeoVec3fPropertyRecPtr norms = GeoVec3fProperty::create(); GeoUInt32PropertyRecPtr inds = GeoUInt32Property::create(); GeoUInt32PropertyRecPtr types = GeoUInt32Property::create(); GeoUInt32PropertyRecPtr lengths = GeoUInt32Property::create(); GeoVec4fPropertyRecPtr cols = GeoVec4fProperty::create(); cout << "SM mesh read: " << sm_types.size() << " " << sm_lengths.size() << " " << sm_pos.size() << " " << sm_norms.size() << " " << sm_inds.size() << " " << sm_cols.size() << endl; if (sm_types.size() > 0) for (auto& t : sm_types) types->addValue(t); if (sm_lengths.size() > 0) for (auto& l : sm_lengths) lengths->addValue(l); for (auto& i : sm_inds) inds->addValue(i); if (sm_pos.size() > 0) for (int i=0; i<sm_pos.size()-2; i+=3) pos->addValue(Pnt3f(sm_pos[i], sm_pos[i+1], sm_pos[i+2])); if (sm_norms.size() > 0) for (int i=0; i<sm_norms.size()-2; i+=3) norms->addValue(Vec3f(sm_norms[i], sm_norms[i+1], sm_norms[i+2])); if (sm_cols.size() > 0) for (int i=0; i<sm_cols.size()-2; i+=3) cols->addValue(Pnt3f(sm_cols[i], sm_cols[i+1], sm_cols[i+2])); cout << "osg mesh data: " << types->size() << " " << lengths->size() << " " << pos->size() << " " << norms->size() << " " << inds->size() << " " << cols->size() << endl; int N = pos->size(); if (N == 0) return; setTypes(types); setLengths(lengths); setPositions(pos); if (norms->size() == N) setNormals(norms); if (cols->size() == N) setColors(cols); setIndices(inds); }