예제 #1
0
void SplinePlugGadget::updateCurve( SplineUIMap::iterator it ) const
{
	SplineffPlugPtr splinePlug = IECore::runTimeCast<SplineffPlug>( it->first );
	IECore::Splineff spline = splinePlug->getValue();
	IECore::Splineff::XInterval interval = spline.interval();
	
	unsigned numPoints = 100;
	
	IECore::V3fVectorDataPtr pd = new IECore::V3fVectorData();
	std::vector<V3f> &p = pd->writable();
	p.resize( numPoints );
	
	for( unsigned i=0; i<numPoints; i++ )
	{
		float x = lerp( interval.lower(), interval.upper(), (float)i / (float)(numPoints-1) );
		float y = spline( x );
		p[i] = V3f( x, y, 0.0f );
	}
	
	IECore::IntVectorDataPtr vertsPerCurve = new IECore::IntVectorData;
	vertsPerCurve->writable().push_back( numPoints );
	
	IECore::CurvesPrimitivePtr curve = new IECore::CurvesPrimitive(
		vertsPerCurve,
		IECore::CubicBasisf::linear(),
		false,
		pd
	);
	
	it->second.curve = curve;
}
예제 #2
0
파일: Primitive.cpp 프로젝트: UIKit0/cortex
const Shader::Setup *Primitive::boundSetup() const
{
	if( m_boundSetup )
	{
		return m_boundSetup.get();
	}
	
	Box3f b = bound();
	IECore::V3fVectorDataPtr pData = new IECore::V3fVectorData();
	std::vector<V3f> &p = pData->writable();
	
	p.push_back( V3f( b.min.x, b.min.y, b.min.z ) );
	p.push_back( V3f( b.max.x, b.min.y, b.min.z ) );
	
	p.push_back( V3f( b.max.x, b.min.y, b.min.z ) );
	p.push_back( V3f( b.max.x, b.max.y, b.min.z	) );
	
	p.push_back( V3f( b.max.x, b.max.y, b.min.z	) );
	p.push_back( V3f( b.min.x, b.max.y, b.min.z	) );
	
	p.push_back( V3f( b.min.x, b.max.y, b.min.z	) );
	p.push_back( V3f( b.min.x, b.min.y, b.min.z ) );
	
	p.push_back( V3f( b.min.x, b.min.y, b.max.z ) );
	p.push_back( V3f( b.max.x, b.min.y, b.max.z ) );
	
	p.push_back( V3f( b.max.x, b.min.y, b.max.z ) );
	p.push_back( V3f( b.max.x, b.max.y, b.max.z	) );
	
	p.push_back( V3f( b.max.x, b.max.y, b.max.z	) );
	p.push_back( V3f( b.min.x, b.max.y, b.max.z	) );
	
	p.push_back( V3f( b.min.x, b.max.y, b.max.z	) );
	p.push_back( V3f( b.min.x, b.min.y, b.max.z ) );
	
	p.push_back( V3f( b.min.x, b.min.y, b.min.z ) );
	p.push_back( V3f( b.min.x, b.min.y, b.max.z ) );

	p.push_back( V3f( b.max.x, b.min.y, b.min.z ) );
	p.push_back( V3f( b.max.x, b.min.y, b.max.z ) );
	
	p.push_back( V3f( b.max.x, b.max.y, b.min.z ) );
	p.push_back( V3f( b.max.x, b.max.y, b.max.z ) );
	
	p.push_back( V3f( b.min.x, b.max.y, b.min.z ) );
	p.push_back( V3f( b.min.x, b.max.y, b.max.z ) );

	m_boundSetup = new Shader::Setup( Shader::constant() );
	m_boundSetup->addVertexAttribute( "P", pData );
	
	return m_boundSetup.get();
}
예제 #3
0
void SceneProcedural::drawLight( const IECore::Light *light, IECore::Renderer *renderer ) const
{	
	AttributeBlock attributeBlock( renderer );

	renderer->setAttribute( "gl:primitive:wireframe", new BoolData( true ) );
	renderer->setAttribute( "gl:primitive:solid", new BoolData( false ) );
	renderer->setAttribute( "gl:curvesPrimitive:useGLLines", new BoolData( true ) );
	renderer->setAttribute( "gl:primitive:wireframeColor", new Color4fData( Color4f( 0.5, 0, 0, 1 ) ) );

	const float a = 0.5f;
	const float phi = 1.0f + sqrt( 5.0f ) / 2.0f;
	const float b = 1.0f / ( 2.0f * phi );
	
	// icosahedron points
	IECore::V3fVectorDataPtr pData = new V3fVectorData;
	vector<V3f> &p = pData->writable();
	p.resize( 24 );
	p[0] = V3f( 0, b, -a );
	p[2] = V3f( b, a, 0 );
	p[4] = V3f( -b, a, 0 );
	p[6] = V3f( 0, b, a );
	p[8] = V3f( 0, -b, a );
	p[10] = V3f( -a, 0, b );
	p[12] = V3f( 0, -b, -a );
	p[14] = V3f( a, 0, -b );
	p[16] = V3f( a, 0, b );
	p[18] = V3f( -a, 0, -b );
	p[20] = V3f( b, -a, 0 );
	p[22] = V3f( -b, -a, 0 );
	
	for( size_t i = 0; i<12; i++ )
	{
		p[i*2] = 2.0f * p[i*2].normalized();
		p[i*2+1] = V3f( 0 );
	}
	
	IntVectorDataPtr vertIds = new IntVectorData;
	vertIds->writable().resize( 12, 2 );
	
	CurvesPrimitivePtr c = new IECore::CurvesPrimitive( vertIds, CubicBasisf::linear(), false, pData );
	c->render( renderer );
}
예제 #4
0
DiskPrimitive::DiskPrimitive( float radius, float z, float thetaMax )
	:	m_radius( radius ), m_z( z ), m_thetaMax( thetaMax ), m_nPoints( 0 )
{
	
	// build vertex attributes for P, N and st, and indexes for triangles.
	
	IECore::V3fVectorDataPtr pData = new IECore::V3fVectorData;
	IECore::V3fVectorDataPtr nData = new IECore::V3fVectorData;
	IECore::V2fVectorDataPtr stData = new IECore::V2fVectorData;
	
	vector<V3f> &pVector = pData->writable();
	vector<V3f> &nVector = nData->writable();
	vector<V2f> &stVector = stData->writable();

	// centre point
	pVector.push_back( V3f( 0.0f, 0.0f, m_z ) );
	nVector.push_back( V3f( 0.0f, 0.0f, 1.0f ) );
	stVector.push_back( V2f( 0.5f, 0.5f ) );

	const unsigned int n = 20;
	float thetaMaxRadians = m_thetaMax/180.0f * M_PI;
	for( unsigned int i=0; i<n; i++ )
	{
		float t = thetaMaxRadians * i/(n-1);
		float x = Math<float>::cos( t );
		float y = Math<float>::sin( t );
		pVector.push_back( V3f( m_radius * x, m_radius * y, m_z ) );
		nVector.push_back( V3f( 0.0f, 0.0f, 1.0f ) );
		stVector.push_back( V2f( x/2.0f + 0.5f, y/2.0f + 0.5f ) );
	}

	m_nPoints = n + 1;
	
	addVertexAttribute( "P", pData );
	addVertexAttribute( "N", nData );
	addVertexAttribute( "st", stData );
}
예제 #5
0
IECore::DataPtr convert( const MCommandResult &result )
{
	MStatus s;
	switch (result.resultType())
	{
		case MCommandResult::kInvalid:
		{
			// No result
			return 0;
		}
		case MCommandResult::kInt:
		{
			int i;
			s = result.getResult(i);
			assert(s);

			IECore::IntDataPtr data = new IECore::IntData();
			data->writable() = i;

			return data;
		}
		case MCommandResult::kIntArray:
		{
			MIntArray v;
			s = result.getResult(v);
			assert(s);
			unsigned sz = v.length();
			IECore::IntVectorDataPtr data = new IECore::IntVectorData();
			data->writable().resize(sz);
			for (unsigned i = 0; i < sz; i++)
			{
				(data->writable())[i] = v[i];
			}

			return data;
		}
		case MCommandResult::kDouble:
		{
			double d;
			s = result.getResult(d);
			assert(s);

			IECore::FloatDataPtr data = new IECore::FloatData();
			data->writable() = static_cast<float>(d);

			return data;
		}
		case MCommandResult::kDoubleArray:
		{
			MDoubleArray v;
			s = result.getResult(v);
			assert(s);
			unsigned sz = v.length();
			IECore::DoubleVectorDataPtr data = new IECore::DoubleVectorData();
			data->writable().resize(sz);
			for (unsigned i = 0; i < sz; i++)
			{
				data->writable()[i] = v[i];
			}

			return data;
		}
		case MCommandResult::kString:
		{
			MString str;
			s = result.getResult(str);
			assert(s);

			IECore::StringDataPtr data = new IECore::StringData();
			data->writable() = std::string(str.asChar());

			return data;
		}
		case MCommandResult::kStringArray:
		{
			MStringArray v;
			s = result.getResult(v);
			assert(s);
			unsigned sz = v.length();
			IECore::StringVectorDataPtr data = new IECore::StringVectorData();
			data->writable().resize(sz);
			for (unsigned i = 0; i < sz; i++)
			{
				data->writable()[i] = std::string(v[i].asChar());
			}

			return data;
		}
		case MCommandResult::kVector:
		{
			MVector v;
			s = result.getResult(v);
			assert(s);

			IECore::V3fDataPtr data = new IECore::V3fData();
			data->writable() = Imath::V3f(v.x, v.y, v.z);

			return data;
		}
		case MCommandResult::kVectorArray:
		{
			MVectorArray v;
			s = result.getResult(v);
			assert(s);
			unsigned sz = v.length();
			IECore::V3fVectorDataPtr data = new IECore::V3fVectorData();
			data->writable().resize(sz);
			for (unsigned i = 0; i < sz; i++)
			{
				data->writable()[i] = Imath::V3f(v[i].x, v[i].y, v[i].z);
			}

			return data;
		}
		case MCommandResult::kMatrix:
		{
			MDoubleArray v;
			int numRows, numColumns;

			s = result.getResult(v, numRows, numColumns);
			assert(s);

			if (numRows > 4 || numColumns > 4)
			{
				throw IECoreMaya::StatusException( MS::kFailure );
			}

			IECore::M44fDataPtr data = new IECore::M44fData();

			for (int i = 0; i < numColumns; i++)
			{
				for (int j = 0; j < numRows; j++)
				{
					(data->writable())[i][j] = v[i*numRows+j];
				}
			}

			return data;
		}
		case MCommandResult::kMatrixArray:
		{
			return 0;
		}
		default:

			assert( false );
			return 0;
	}
}
예제 #6
0
SpherePrimitive::SpherePrimitive( float radius, float zMin, float zMax, float thetaMax )
	:	m_radius( radius ), m_zMin( zMin ), m_zMax( zMax ), m_thetaMax( thetaMax ), m_vertIdsBuffer( 0 )
{
	// figure out bounding box
	
	thetaMax = m_thetaMax/180.0f * M_PI;
	float minX = m_radius * ( thetaMax < M_PI ? Math<float>::cos( thetaMax ) : -1.0f );
	float maxY = m_radius * ( thetaMax < M_PI/2 ? Math<float>::sin( thetaMax ) : 1.0f );
	float minY = m_radius * ( thetaMax > 3 * M_PI/2 ? -1.0f : min( 0.0f, Math<float>::sin( thetaMax ) ) );
	m_bound = Imath::Box3f( V3f( minX, minY, m_zMin * m_radius ), V3f( m_radius, maxY, m_zMax * m_radius ) );
	
	// build vertex attributes for P, N and st, and indexes for triangles.
	
	IECore::V3fVectorDataPtr pData = new IECore::V3fVectorData;
	IECore::V3fVectorDataPtr nData = new IECore::V3fVectorData;
	IECore::V2fVectorDataPtr stData = new IECore::V2fVectorData;
	m_vertIds = new IECore::UIntVectorData;
	
	vector<V3f> &pVector = pData->writable();
	vector<V3f> &nVector = nData->writable();
	vector<V2f> &stVector = stData->writable();
	vector<unsigned int> &vertIdsVector = m_vertIds->writable();
	
	float oMin = Math<float>::asin( m_zMin );
	float oMax = Math<float>::asin( m_zMax );
	const unsigned int nO = max( 4u, (unsigned int)( 20.0f * (oMax - oMin) / M_PI ) );

	thetaMax = m_thetaMax/180.0f * M_PI;
	const unsigned int nT = max( 7u, (unsigned int)( 40.0f * thetaMax / (M_PI*2) ) );

	for( unsigned int i=0; i<nO; i++ )
	{
		float v = (float)i/(float)(nO-1);
		float o = lerp( oMin, oMax, v );
		float z = m_radius * Math<float>::sin( o );
		float r = m_radius * Math<float>::cos( o );

		for( unsigned int j=0; j<nT; j++ )
		{
			float u = (float)j/(float)(nT-1);
			float theta = thetaMax * u;
			V3f p( r * Math<float>::cos( theta ), r * Math<float>::sin( theta ), z );
			stVector.push_back( V2f( u, v ) );
			pVector.push_back( p );
			nVector.push_back( p );
			if( i < nO - 1 && j < nT - 1 )
			{
				unsigned int i0 = i * nT + j;
				unsigned int i1 = i0 + 1;
				unsigned int i2 = i0 + nT;
				unsigned int i3 = i2 + 1;
				vertIdsVector.push_back( i0 );
				vertIdsVector.push_back( i1 );
				vertIdsVector.push_back( i2 );
				vertIdsVector.push_back( i1 );
				vertIdsVector.push_back( i3 );
				vertIdsVector.push_back( i2 );
			}
		}
	}
	
	addVertexAttribute( "P", pData );
	addVertexAttribute( "N", nData );
	addVertexAttribute( "st", stData );
}
IECore::PrimitivePtr FromMayaCurveConverter::doPrimitiveConversion( MFnNurbsCurve &fnCurve ) const
{
	// decide on the basis and periodicity
	int mDegree = fnCurve.degree();
	IECore::CubicBasisf basis = IECore::CubicBasisf::linear();
	if( m_linearParameter->getTypedValue()==false && mDegree==3 )
	{
		basis = IECore::CubicBasisf::bSpline();
	}
	bool periodic = false;
	if( fnCurve.form()==MFnNurbsCurve::kPeriodic )
	{
		periodic = true;
	}

	// get the points and convert them
	MPointArray mPoints;
	fnCurve.getCVs( mPoints, space() );
	if( periodic )
	{
		// maya duplicates the first points at the end, whereas we just wrap around.
		// remove the duplicates.
		mPoints.setLength( mPoints.length() - mDegree );
	}

	bool duplicateEnds = false;
	if( !periodic && mDegree==3 )
	{
		// there's an implicit duplication of the end points that we need to make explicit
		duplicateEnds = true;
	}

	IECore::V3fVectorDataPtr pointsData = new IECore::V3fVectorData;
	std::vector<Imath::V3f> &points = pointsData->writable();
	std::vector<Imath::V3f>::iterator transformDst;
	if( duplicateEnds )
	{
		points.resize( mPoints.length() + 4 );
		transformDst = points.begin();
		*transformDst++ = IECore::convert<Imath::V3f>( mPoints[0] );
		*transformDst++ = IECore::convert<Imath::V3f>( mPoints[0] );
	}
	else
	{
		points.resize( mPoints.length() );
		transformDst = points.begin();
	}

	std::transform( MArrayIter<MPointArray>::begin( mPoints ), MArrayIter<MPointArray>::end( mPoints ), transformDst, IECore::VecConvert<MPoint, V3f>() );

	if( duplicateEnds )
	{
		points[points.size()-1] = IECore::convert<Imath::V3f>( mPoints[mPoints.length()-1] );
		points[points.size()-2] = IECore::convert<Imath::V3f>( mPoints[mPoints.length()-1] );
	}

	// make and return the curve
	IECore::IntVectorDataPtr vertsPerCurve = new IECore::IntVectorData;
	vertsPerCurve->writable().push_back( points.size() );

	return new IECore::CurvesPrimitive( vertsPerCurve, basis, periodic, pointsData );
}