GeoNormalDifferenceSetPtr GeoNormalDifferenceSet::create(const GeoNormalsPtr BaseNormals, const GeoNormalsPtr ToNormals) { //Check that both Normal Containers have the same number of Values if(BaseNormals == NullFC || ToNormals == NullFC || BaseNormals->getSize() != ToNormals->getSize()) { return NullFC; } GeoNormalDifferenceSetPtr Result = GeoNormalDifferenceSetBase::create(); Result->setIndices( GeoIndicesUI32::create() ); Result->setNormals( createEmptyFromBase(BaseNormals) ); //Loop through each position of BaseNormals and ToNormals beginEditCP(Result); Result->getIndices()->push_back( -1 ); for(UInt32 i=0 ; i<BaseNormals->getSize() ; ++i) { //If Normal i of ToNormals is different from BaseNormals if(ToNormals->getValue(i) != BaseNormals->getValue(i)) { //Then add this Normal and its index to the DifferenceSet addValueAsBaseType(Result->getNormals(), ToNormals, i); if(Result->getIndices()->getValue(0) != -1) { Result->getIndices()->push_back( i ); } else { Result->getIndices()->setValue( i, 0 ); } } } endEditCP(Result); return Result; }
void FaceSpatializeIndexed<BasicTraits>::CategoryRaw::addData (OpenSGFaceBase<OpenSGTraits>* node, const FaceIterator& face) { GeoPositions3f::StoredFieldType* p = m_coord->getFieldPtr(); GeoNormals3f::StoredFieldType* n = m_normal->getFieldPtr(); //GeoIndicesUI32::StoredFieldType* i = m_index->getFieldPtr(); // find offset of positions and normals in the new geometry u32 i, k; m_offsetIt = m_offset.find(face.getGeometry()); if (m_offsetIt == m_offset.end()) { // insert new offsets entry into map HashMapPair offsetPair = m_offset.insert(HashMap::value_type(face.getGeometry(), quad())); m_offsetIt = offsetPair.first; m_offsetIt->second.position = m_coord->size(); GeoPositionsPtr faceP = m_original.getPositions(); addRefCP(faceP); for (k=0; k<faceP->getSize(); ++k) { p->addValue(faceP->getValue(k)); } if (m_hasNormal) { m_offsetIt->second.normal = m_normal->size(); GeoNormalsPtr faceN = m_original.getNormals(); addRefCP(faceN); for (k=0; k<faceN->getSize(); ++k) { n->addValue(faceN->getValue(k)); } subRefCP(faceN); } subRefCP(faceP); } // insert indices if (face.getLength() == 3) { for (k=0; k<3; ++k) { m_index->insertValue(face.getPositionIndex(k)+m_offsetIt->second.position, m_quadOffset++); i = 1; if (m_hasNormal) { m_index->insertValue(face.getNormalIndex(k)+m_offsetIt->second.normal, m_quadOffset++); ++i; } for (; i<m_indexStride; ++i) { m_index->insertValue(0, m_quadOffset++); } } } else { for (k=0; k<4; ++k) { m_index->addValue(face.getPositionIndex(k)+m_offsetIt->second.position); i = 1; if (m_hasNormal) { m_index->addValue(face.getNormalIndex(k)+m_offsetIt->second.normal); ++i; } for (; i<m_indexStride; ++i) { m_index->addValue(0); } } } }
void FaceSpatialize<BasicTraits>::CategoryRaw::addData (OpenSGFaceBase<OpenSGTraits>* node, const FaceIterator& face) { GeoPositions3f::StoredFieldType* p = m_coord->getFieldPtr(); GeoNormals3f::StoredFieldType* n = m_normal->getFieldPtr(); //GeoIndicesUI32::StoredFieldType* i = m_index->getFieldPtr(); GeoPositionsPtr faceP = node->getPositions(); addRefCP(faceP); u32 k; for (k=0; k<faceP->getSize(); ++k) { p->addValue(faceP->getValue(k)); if (face.getLength()==3) { m_index->insertValue(p->size()-1, m_quadOffset++); } else { m_index->addValue(p->size()-1); } } if (!m_hasNormal) { #if 1 Vec3f p0(faceP->getValue(0)); Vec3f p1(faceP->getValue(1)); Vec3f p2(faceP->getValue(2)); p2 -= p1; p0 -= p1; if (m_ccw) { p0.crossThis(p2); p0.normalize(); n->addValue(p0); } else { p2.crossThis(p0); p2.normalize(); n->addValue(p2); } #endif } else { // per-vertex normals or per-face normals GeoNormalsPtr faceN = node->getNormals(); addRefCP(faceN); for (k=0; k<faceN->getSize(); ++k) { n->addValue(faceN->getValue(k)); } subRefCP(faceN); } subRefCP(faceP); }