void modify_geometry(int obj, Scene& scene, GeometryList& out) { PointList* points = out.writable_points(obj); const unsigned n = points->size(); // Transform points: if (swap) { // POW for (unsigned i = 0; i < n; i++) { Vector3& v = (*points)[i]; if (clamp_black) { if (v.x <= 0.0f) v.x = 0; else v.x = pow(v.x, log.x); if (v.y <= 0.0f) v.y = 0; else v.y = pow(v.y, log.y); if (v.z <= 0.0f) v.z = 0; else v.z = pow(v.z, log.z); } else { v.x = (v.x > 0.0f) ? pow(v.x, log.x) : -pow(-v.x, log.x); v.y = (v.y > 0.0f) ? pow(v.y, log.y) : -pow(-v.y, log.y); v.z = (v.z > 0.0f) ? pow(v.z, log.z) : -pow(-v.z, log.z); } } } else { // LOG for (unsigned i = 0; i < n; i++) { Vector3& v = (*points)[i]; v.x = pow(log.x, v.x) - 1.0f; v.y = pow(log.y, v.y) - 1.0f; v.z = pow(log.z, v.z) - 1.0f; } } }
void MeshToNukeGeometryConverter::doConversion( const IECore::Object *from, GeometryList &to, int objIndex, const IECore::CompoundObject *operands ) const { assert( from ); const MeshPrimitive *mesh = static_cast<const MeshPrimitive *>( from ); const std::vector<int> &vertPerFace = mesh->verticesPerFace()->readable(); const std::vector<int> &vertIds = mesh->vertexIds()->readable(); std::vector<int>::const_iterator ids = vertIds.begin(); // create polygons for ( std::vector<int>::const_iterator vpf = vertPerFace.begin(); vpf != vertPerFace.end(); vpf++ ) { Polygon *p = new Polygon( *vpf, true ); for ( int v = 0; v < *vpf; v++, ids++ ) { p->vertex(v) = *ids; } to.add_primitive( objIndex, p ); } // get points // \todo: add parameters for standard prim vars const V3fVectorData *meshPoints = mesh->variableData< V3fVectorData >( "P", PrimitiveVariable::Vertex ); if ( meshPoints ) { unsigned numPoints = meshPoints->readable().size(); PointList* points = to.writable_points( objIndex ); points->resize( numPoints ); std::transform( meshPoints->readable().begin(), meshPoints->readable().end(), points->begin(), IECore::convert< DD::Image::Vector3, Imath::V3f > ); } // get normals const V3fVectorData *meshNormals = mesh->variableData< V3fVectorData >( "N", PrimitiveVariable::Vertex ); if ( meshNormals ) { Attribute* N = to.writable_attribute( objIndex, Group_Points, "N", NORMAL_ATTRIB); unsigned p = 0; for ( std::vector< Imath::V3f >::const_iterator nIt = meshNormals->readable().begin(); nIt < meshNormals->readable().end(); nIt++, p++) { N->normal(p) = IECore::convert< Vector3, Imath::V3f >( *nIt ); } } // get uvs PrimitiveVariableMap::const_iterator uvIt = mesh->variables.find( "uv" ); if( uvIt != mesh->variables.end() && uvIt->second.interpolation == PrimitiveVariable::FaceVarying && uvIt->second.data->typeId() == V2fVectorDataTypeId ) { Attribute* uv = to.writable_attribute( objIndex, Group_Vertices, "uv", VECTOR4_ATTRIB ); if( uvIt->second.indices ) { const std::vector<Imath::V2f> &uvs = runTimeCast<V2fVectorData>( uvIt->second.data )->readable(); const std::vector<int> &indices = uvIt->second.indices->readable(); for( size_t i = 0; i < indices.size() ; ++i ) { // as of Cortex 10, we take a UDIM centric approach // to UVs, which clashes with Nuke, so we must flip // the v values during conversion. uv->vector4( i ).set( uvs[indices[i]][0], 1.0 - uvs[indices[i]][1], 0.0f, 1.0f ); } } else { const std::vector<Imath::V2f> &uvs = runTimeCast<V2fVectorData>( uvIt->second.data )->readable(); for( size_t i = 0; i < uvs.size() ; ++i ) { // as of Cortex 10, we take a UDIM centric approach // to UVs, which clashes with Nuke, so we must flip // the v values during conversion. uv->vector4( i ).set( uvs[i][0], 1.0 - uvs[i][1], 0.0f, 1.0f ); } } } // get colours const Color3fVectorData *meshColours = mesh->variableData< Color3fVectorData >( "Cs", PrimitiveVariable::FaceVarying ); if ( meshColours ) { Attribute *Cf = to.writable_attribute( objIndex, Group_Vertices, "Cf", VECTOR4_ATTRIB ); unsigned v = 0; for ( std::vector< Imath::Color3f >::const_iterator cIt = meshColours->readable().begin(); cIt < meshColours->readable().end(); cIt++, v++) { Cf->vector4( v ).set( (*cIt)[0], (*cIt)[1], (*cIt)[2], 1 ); } } // \todo Implement custom prim vars... }
/*virtual*/ void ABCReadGeo::create_geometry(Scene& scene, GeometryList& out) { if (filename()[0] == '\0') { out.delete_objects(); return; } IArchive archive( Alembic::AbcCoreHDF5::ReadArchive(), filename(),//archiveName, Abc::ErrorHandler::kQuietNoopPolicy ); if (!archive.valid()) { std::cout << "error reading archive" << std::endl; error("Unable to read file"); return; } IObject archiveTop = archive.getTop(); std::vector<Alembic::AbcGeom::IObject> _objs; getABCGeos(archiveTop, _objs); // current Time to sample from chrono_t curTime = m_sampleFrame / _FPS; if ( rebuild(Mask_Primitives)) { out.delete_objects(); } int obj = 0; for( std::vector<Alembic::AbcGeom::IObject>::const_iterator iObj( _objs.begin() ); iObj != _objs.end(); ++iObj ) { // Leave an empty obj if knob is unchecked if (!active_objs[obj] ) { out.add_object(obj); PointList& points = *out.writable_points(obj); points.resize(0); out[obj].delete_group_attribute(Group_Vertices,kUVAttrName, VECTOR4_ATTRIB); obj++; continue; } if ( rebuild(Mask_Primitives)) { out.add_object(obj); if (bbox_objs[obj]) { //(bbox_mode) { buildBboxPrimitives(out, obj); } else { buildABCPrimitives(out, obj, *iObj, curTime); } } if ( rebuild(Mask_Points)) { PointList& points = *out.writable_points(obj); if (bbox_objs[obj]) { //(bbox_mode) { Imath::Box3d bbox = getBounds(*iObj, curTime); points.resize(8); IObject iObj_copy(*iObj); Matrix4 xf = getConcatMatrix(iObj_copy,curTime, interpolate !=0); // for some reason getParent() won't take a const IObject, hence the copy... // Add bbox corners for (unsigned i = 0; i < 8; i++) { Vector3 pt((i&4)>>2 ? bbox.max.x : bbox.min.x, (i&2)>>1 ? bbox.max.y : bbox.min.y, (i%2) ? bbox.max.z : bbox.min.z ); points[i] = xf.transform(pt); } } else{ writePoints(*iObj, points, curTime, interpolate !=0); } } if ( rebuild(Mask_Attributes)) { if (bbox_objs[obj]) { //(bbox_mode) out[obj].delete_group_attribute(Group_Vertices,kUVAttrName, VECTOR4_ATTRIB); } else { // set UVs Attribute* UV = out.writable_attribute(obj, Group_Vertices, kUVAttrName, VECTOR4_ATTRIB); IV2fGeomParam uvParam = getUVsParam(*iObj); setUVs(out[obj], uvParam, UV, curTime); // set Normals IN3fGeomParam nParam = getNsParam(*iObj); if (nParam.valid()) { Attribute* N = out.writable_attribute(obj, Group_Vertices, kNormalAttrName, NORMAL_ATTRIB); setNormals(out[obj], nParam, N, curTime); } } } obj++; }