bool outputCoordinateSystem( const ScenePlug *scene, const ScenePlug::ScenePath &path, IECore::Renderer *renderer ) { IECore::ConstCoordinateSystemPtr constCoordinateSystem = runTimeCast<const IECore::CoordinateSystem>( scene->object( path ) ); if( !constCoordinateSystem ) { return false; } if( !visible( scene, path ) ) { return false; } const M44f transform = scene->fullTransform( path ); std::string coordinateSystemName; ScenePlug::pathToString( path, coordinateSystemName ); CoordinateSystemPtr coordinateSystem = constCoordinateSystem->copy(); coordinateSystem->setName( coordinateSystemName ); { TransformBlock transformBlock( renderer ); renderer->concatTransform( transform ); coordinateSystem->render( renderer ); } return true; }
ConstObjectPtr SOP_SceneCacheSource::transformObject( const IECore::Object *object, const Imath::M44d &transform, bool &hasAnimatedTopology, bool &hasAnimatedPrimVars, std::vector<InternedString> &animatedPrimVars ) { if ( const Primitive *primitive = IECore::runTimeCast<const Primitive>( object ) ) { TransformOpPtr transformer = new TransformOp(); transformer->inputParameter()->setValue( const_cast<Primitive*>( primitive ) ); // safe because we set the copy parameter transformer->copyParameter()->setTypedValue( true ); transformer->matrixParameter()->setValue( new M44dData( transform ) ); ObjectPtr result = transformer->operate(); std::vector<std::string> &primVars = transformer->primVarsParameter()->getTypedValue(); for ( std::vector<std::string>::iterator it = primVars.begin(); it != primVars.end(); ++it ) { if ( std::find( animatedPrimVars.begin(), animatedPrimVars.end(), *it ) == animatedPrimVars.end() ) { animatedPrimVars.push_back( *it ); hasAnimatedPrimVars = true; } } return result; } else if ( const Group *group = IECore::runTimeCast<const Group>( object ) ) { GroupPtr result = group->copy(); MatrixTransformPtr matTransform = matrixTransform( transform ); matTransform->matrix *= group->getTransform()->transform(); result->setTransform( matTransform ); return result; } else if ( const CoordinateSystem *coord = IECore::runTimeCast<const CoordinateSystem>( object ) ) { CoordinateSystemPtr result = coord->copy(); MatrixTransformPtr matTransform = matrixTransform( transform ); matTransform->matrix *= coord->getTransform()->transform(); result->setTransform( matTransform ); return result; } return object; }
ConstObjectPtr SOP_SceneCacheSource::transformObject( const IECore::Object *object, const Imath::M44d &transform, Parameters ¶ms ) { if ( const Primitive *primitive = IECore::runTimeCast<const Primitive>( object ) ) { TransformOpPtr transformer = new TransformOp(); transformer->inputParameter()->setValue( const_cast<Primitive*>( primitive ) ); // safe because we set the copy parameter transformer->copyParameter()->setTypedValue( true ); transformer->matrixParameter()->setValue( new M44dData( transform ) ); // add all Point and Normal prim vars to the transformation list, except for rest/Pref const PrimitiveVariableMap &variables = primitive->variables; std::vector<std::string> &primVars = transformer->primVarsParameter()->getTypedValue(); primVars.clear(); for ( PrimitiveVariableMap::const_iterator it = variables.begin(); it != variables.end(); ++it ) { if ( despatchTypedData<TransformGeometricData, IECore::TypeTraits::IsGeometricTypedData, DespatchTypedDataIgnoreError>( it->second.data.get() ) ) { // we don't want to alter rest/Pref because Houdini excepts these to be non-transforming prim vars if ( it->first == "rest" || it->first == "Pref" ) { continue; } primVars.push_back( it->first ); // add the transforming prim vars to the animated list if ( std::find( params.animatedPrimVars.begin(), params.animatedPrimVars.end(), it->first ) == params.animatedPrimVars.end() ) { params.animatedPrimVars.push_back( it->first ); params.hasAnimatedPrimVars = true; } } } return transformer->operate(); } else if ( const Group *group = IECore::runTimeCast<const Group>( object ) ) { GroupPtr result = group->copy(); MatrixTransformPtr matTransform = matrixTransform( transform ); if ( const Transform *transform = group->getTransform() ) { matTransform->matrix *= transform->transform(); } result->setTransform( matTransform ); return result; } else if ( const CoordinateSystem *coord = IECore::runTimeCast<const CoordinateSystem>( object ) ) { CoordinateSystemPtr result = coord->copy(); MatrixTransformPtr matTransform = matrixTransform( transform ); if ( const Transform *transform = coord->getTransform() ) { matTransform->matrix *= transform->transform(); } result->setTransform( matTransform ); return result; } return object; }
IECore::ObjectPtr FromMayaLocatorConverter::doConversion( const MDagPath &dagPath, IECore::ConstCompoundObjectPtr operands ) const { MStatus st; bool hasLocator = dagPath.hasFn( MFn::kLocator, &st ); if (!st || !hasLocator) { throw Exception( "Could not find locator!" ); } MObject locatorObj = dagPath.node(); if ( !locatorObj.hasFn( MFn::kLocator ) ) { throw Exception( "Not a locator!" ); } MFnDagNode fnLocator( locatorObj ); CoordinateSystemPtr result = new CoordinateSystem; result->setName( IECore::convert<std::string>( fnLocator.name() ) ); /// obtain local position and scale from locator Imath::V3f position(0), scale(0); MPlug positionPlug = fnLocator.findPlug( "localPositionX", &st ); if ( !st ) throw Exception("Could not find 'localPositionX' plug!"); positionPlug.getValue(position[0]); positionPlug = fnLocator.findPlug( "localPositionY", &st ); if ( !st ) throw Exception("Could not find 'localPositionY' plug!"); positionPlug.getValue(position[1]); positionPlug = fnLocator.findPlug( "localPositionZ", &st ); if ( !st ) throw Exception("Could not find 'localPositionZ' plug!"); positionPlug.getValue(position[2]); MPlug scalePlug = fnLocator.findPlug( "localScaleX", &st ); if ( !st ) throw Exception("Could not find 'localScaleX' plug!"); scalePlug.getValue(scale[0]); scalePlug = fnLocator.findPlug( "localScaleY", &st ); if ( !st ) throw Exception("Could not find 'localScaleY' plug!"); scalePlug.getValue(scale[1]); scalePlug = fnLocator.findPlug( "localScaleZ", &st ); if ( !st ) throw Exception("Could not find 'localScaleZ' plug!"); scalePlug.getValue(scale[2]); Imath::M44f scaleM,translateM; scaleM.scale(scale); translateM.translate(position); result->setTransform( new MatrixTransform( scaleM * translateM ) ); return result; }