Esempio n. 1
0
	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
			}
		}
	}
Esempio n. 2
0
	// 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);
			}
		}
	}
Esempio n. 3
0
	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 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...
}
Esempio n. 5
0
/*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++;
	}