AtomicPtr LoaderDFF::readAtomic(FrameList &framelist, GeometryList &geometrylist, const RWBStream &stream) { auto atomicStream = stream.getInnerStream(); auto atomicStructID = atomicStream.getNextChunk(); if (atomicStructID != CHUNK_STRUCT) { throw DFFLoaderException("Atomic missing struct chunk"); } auto data = atomicStream.getCursor(); auto frame = *(std::uint32_t *)data; data += sizeof(std::uint32_t); auto geometry = *(std::uint32_t *)data; data += sizeof(std::uint32_t); auto flags = *(std::uint32_t *) data; // Verify the atomic's particulars RW_CHECK(frame < framelist.size(), "atomic frame " << frame << " out of bounds"); RW_CHECK(geometry < geometrylist.size(), "atomic geometry " << geometry << " out of bounds"); auto atomic = std::make_shared<Atomic>(); if (geometry < geometrylist.size()) { atomic->setGeometry(geometrylist[geometry]); } if (frame < framelist.size()) { atomic->setFrame(framelist[frame]); } atomic->setFlags(flags); return atomic; }
void modify_geometry(int obj, Scene& scene, GeometryList& out) { // Call the engine on all the caches: for (unsigned i = 0; i < out.objects(); i++) { GeoInfo& info = out[i]; // Copy over old UV attributes keep_uvs(i, info, out); // Reusable pointer for the attribute we are going to be writing to Attribute* uv; // Copy over pt attributes uv = out.writable_attribute(i, Group_Points, uv_attrib_name, VECTOR4_ATTRIB); transform_each_element_in_attribute(uv, info.points()); // If the previously detected group type is vertex attribute we need to modify it as well // since vertex attribs take precedence and say a Sphere in Nuke has vertex attribs // as opposed to point attribs :-( so justified double work here if(t_group_type == Group_Vertices) { uv = out.writable_attribute(i, Group_Vertices, uv_attrib_name, VECTOR4_ATTRIB); transform_each_element_in_attribute(uv, info.vertices()); // Copy over vertex attributes } } }
void ToNukeGeometryConverter::convert( GeometryList &geoList ) const { int objIndex = m_objIndexParameter->getNumericValue(); if ( objIndex == -1 ) { objIndex = (int)geoList.objects(); } geoList.add_object(objIndex); ConstCompoundObjectPtr operands = parameters()->getTypedValidatedValue<CompoundObject>(); doConversion( srcParameter()->getValidatedValue(), geoList, objIndex, operands.get() ); }
// This is needed to preserve UVs which are already there void keep_uvs(int index, GeoInfo& info, GeometryList& out) { // get the original uv attribute used to restore untouched uv coordinate const AttribContext* context = info.get_attribcontext(uv_attrib_name); AttributePtr uv_original = context ? context->attribute : AttributePtr(); if(!uv_original){ Op::error( "Missing \"%s\" channel from geometry", uv_attrib_name ); return; } DD::Image::GroupType t_group_type = context->group; // texture coordinate group type // we have two possibilities: // the uv coordinate are stored in Group_Points or in Group_Vertices way // sanity check assert(t_group_type == Group_Points || t_group_type == Group_Vertices); // create a buffer to write on it Attribute* uv = out.writable_attribute(index, t_group_type, uv_attrib_name, VECTOR4_ATTRIB); assert(uv); // copy all original texture coordinate if available if (uv_original){ // sanity check assert(uv->size() == uv_original->size()); for (unsigned i = 0; i < uv->size(); i++) { uv->vector4(i) = uv_original->vector4(i); } } }
void modify_geometry(int obj, Scene& scene, GeometryList& out) { const char* uv_attrib_name = "uv"; // Call the engine on all the caches: for (unsigned i = 0; i < out.objects(); i++) { GeoInfo& info = out[i]; // Copy over old UV attributes keep_uvs(i, info, out); // TODO: investigate difference between vertex and point UVs // Create a point attribute Attribute* uv = out.writable_attribute(i, Group_Points, uv_attrib_name, VECTOR4_ATTRIB); if(!uv) return; for (unsigned p = 0; p < info.points(); p++) { distorter.distort_uv(uv->vector4(p)); } } }
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... }
// Generates the geometry required to render a single line of text. int FontFaceHandle::GenerateString(GeometryList& geometry, const WString& string, const Vector2f& position, const Colourb& colour, int layer_configuration_index, word default_character) const { int geometry_index = 0; int line_width = 0; ROCKET_ASSERT(layer_configuration_index >= 0); ROCKET_ASSERT(layer_configuration_index < (int) layer_configurations.size()); // Fetch the requested configuration and generate the geometry for each one. const LayerConfiguration& layer_configuration = layer_configurations[layer_configuration_index]; for (size_t i = 0; i < layer_configuration.size(); ++i) { FontFaceLayer* layer = layer_configuration[i]; Colourb layer_colour; if (layer == base_layer) layer_colour = colour; else layer_colour = layer->GetColour(); // Resize the geometry list if required. if ((int) geometry.size() < geometry_index + layer->GetNumTextures()) geometry.resize(geometry_index + layer->GetNumTextures()); // Bind the textures to the geometries. for (int i = 0; i < layer->GetNumTextures(); ++i) geometry[geometry_index + i].SetTexture(layer->GetTexture(i)); line_width = 0; word prior_character = 0; const word* string_iterator = string.CString(); const word* string_end = string.CString() + string.Length(); word final_character; for (; string_iterator != string_end; string_iterator++) { final_character = *string_iterator; FontGlyphMap::const_iterator iterator = glyphs.find(*string_iterator); if (iterator == glyphs.end()) { if (default_character >= 32) { iterator = glyphs.find(default_character); if (iterator == glyphs.end()) { continue; } else { final_character = default_character; } } else { continue; } } // Adjust the cursor for the kerning between this character and the previous one. if (prior_character != 0) line_width += GetKerning(prior_character, final_character); layer->GenerateGeometry(&geometry[geometry_index], final_character, Vector2f(position.x + line_width, position.y), layer_colour); line_width += iterator->second.advance; prior_character = final_character; } geometry_index += layer->GetNumTextures(); } // Cull any excess geometry from a previous generation. geometry.resize(geometry_index); return line_width; }
/*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++; }