GA_Detail::IOStatus GEO_CobIOTranslator::fileSaveToFile( const GEO_Detail *geo, ostream &os, const char *fileName ) { ((ofstream&)os).close(); GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)geo, false ); FromHoudiniGeometryConverterPtr converter = FromHoudiniGeometryConverter::create( handle ); if ( !converter ) { return false; } ObjectPtr object = converter->convert(); if ( !object ) { return false; } try { WriterPtr writer = Writer::create( object, fileName ); writer->write(); } catch ( IECore::Exception e ) { return false; } return true; }
ObjectPtr FromHoudiniGroupConverter::doDetailConversion( const GU_Detail *geo, const CompoundObject *operands ) const { GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)geo, false ); FromHoudiniGeometryConverterPtr converter = FromHoudiniGeometryConverter::create( handle ); if ( !converter || converter->isInstanceOf( FromHoudiniGroupConverter::staticTypeId() ) ) { /// \todo: if we're in PrimitiveGroup mode, but names exist, we return 0 when we should be returning a Group return 0; } // transfer the common parameter values CompoundParameter *parameters = converter->parameters(); const CompoundParameter::ParameterMap ¶meterMap = parameters->parameters(); const CompoundObject::ObjectMap &values = operands->members(); for ( CompoundObject::ObjectMap::const_iterator it = values.begin(); it != values.end(); ++it ) { CompoundParameter::ParameterMap::const_iterator pIt = parameterMap.find( it->first ); if ( pIt != parameterMap.end() && pIt->second->defaultValue()->typeId() == it->second->typeId() ) { parameters->setParameterValue( it->first, it->second ); } } return converter->convert(); }
GEO_Primitive *GU_CortexPrimitive::doConvert( GU_ConvertParms &parms ) { if ( !m_object ) { return 0; } #if UT_MAJOR_VERSION_INT >= 13 GA_PrimCompat::TypeMask type = parms.toType(); #else GA_PrimCompat::TypeMask type = parms.toType; #endif /// \todo: should the GEO_PrimTypeCompat be registered with the converters? if ( m_object->isInstanceOf( IECore::MeshPrimitiveTypeId ) && type == GEO_PrimTypeCompat::GEOPRIMPOLY ) { GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)getParent(), false ); ToHoudiniPolygonsConverterPtr converter = new ToHoudiniPolygonsConverter( IECore::runTimeCast<const IECore::MeshPrimitive>( m_object.get() ) ); if ( !converter->convert( handle ) ) { return 0; } } /// \todo: support for CurvesPrimitive, PointsPrimitive, and any other existing converters return 0; }
GA_Detail::IOStatus GEO_CobIOTranslator::fileLoad( GEO_Detail *geo, UT_IStream &is, int ate_magic ) { ((UT_IFStream&)is).close(); ConstVisibleRenderablePtr renderable = 0; try { ReaderPtr reader = Reader::create( is.getLabel() ); if ( reader->isInstanceOf( ParticleReaderTypeId ) ) { reader->parameters()->parameter<IntParameter>( "realType" )->setNumericValue( ParticleReader::Float ); } renderable = runTimeCast<VisibleRenderable>( reader->read() ); } catch ( IECore::Exception e ) { return false; } if ( !renderable ) { return false; } ToHoudiniGeometryConverterPtr converter = ToHoudiniGeometryConverter::create( renderable ); if ( !converter ) { return false; } GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)geo, false ); return converter->convert( handle ); }
GA_Detail::IOStatus GEO_CobIOTranslator::fileLoad( GEO_Detail *geo, UT_IStream &is, int ate_magic ) { ((UT_IFStream&)is).close(); ConstObjectPtr object = 0; try { ReaderPtr reader = Reader::create( is.getLabel() ); if ( !reader ) { return false; } object = reader->read(); } catch ( IECore::Exception e ) { return false; } if ( !object ) { return false; } ToHoudiniGeometryConverterPtr converter = ToHoudiniGeometryConverter::create( object.get() ); if ( !converter ) { return false; } GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)geo, false ); return converter->convert( handle ); }
void IECoreMantra::ProceduralPrimitive::addVisibleRenderable( VisibleRenderablePtr renderable ) { ToHoudiniGeometryConverterPtr converter = ToHoudiniGeometryConverter::create( renderable ); if( !converter ) { msg( Msg::Warning, "ProceduralPrimitive::addVisibleRenderable", "converter could not be found" ); return; } GU_Detail *gdp = allocateGeometry(); GU_DetailHandle handle; handle.allocateAndSet( (GU_Detail*)gdp, false ); bool converted = converter->convert( handle ); if ( !converted ) { msg( Msg::Warning, "ProceduralPrimitive::addVisibleRenderable", "converter failed" ); return; } /// \todo ToHoudiniGeometryConverter does not create a Houdini style uv attribute. /// We make one from s and t. This code should probably live in a converter or in an Op that /// remaps IECore conventions to common Houdini ones. MeshPrimitivePtr mesh = runTimeCast<MeshPrimitive> (renderable); if ( mesh ) { gdp->addTextureAttribute( GA_ATTRIB_VERTEX ); GEO_AttributeHandle auv = gdp->getAttribute( GA_ATTRIB_VERTEX, "uv" ); GEO_AttributeHandle as = gdp->getAttribute( GA_ATTRIB_VERTEX, "s" ); GEO_AttributeHandle at = gdp->getAttribute( GA_ATTRIB_VERTEX, "t" ); if ( auv.isAttributeValid() && as.isAttributeValid() && at.isAttributeValid() ) { GA_GBPrimitiveIterator it( *gdp ); GA_Primitive *p = it.getPrimitive(); while ( p ) { for (int i = 0; i < p->getVertexCount(); ++i) { GA_Offset v = p->getVertexOffset(i); as.setVertex(v); at.setVertex(v); auv.setVertex(v); auv.setF( as.getF(0), 0 ); auv.setF( ((at.getF(0) * -1.0f) + 1.0f), 1 ); // wat, t arrives upside down for some reason. auv.setF( 0.0f, 2 ); } ++it; p = it.getPrimitive(); } } } if ( m_renderer->m_motionType == RendererImplementation::Geometry ) { msg(Msg::Debug, "IECoreMantra::ProceduralPrimitive::addVisibleRenderable", "MotionBlur:Geometry" ); if ( !m_renderer->m_motionTimes.empty() ) { if ( (size_t)m_renderer->m_motionSize == m_renderer->m_motionTimes.size() ) { openGeometryObject(); } addGeometry(gdp, m_renderer->m_motionTimes.front()); m_renderer->m_motionTimes.pop_front(); if ( m_renderer->m_motionTimes.empty() ) { applySettings(); closeObject(); } } } else if ( m_renderer->m_motionType == RendererImplementation::ConcatTransform || m_renderer->m_motionType == RendererImplementation::SetTransform ) { // It isn't clear that this will give correct results. // ConcatTransform may need to interpolate transform snapshots. msg(Msg::Debug, "IECoreMantra::ProceduralPrimitive::addVisibleRenderable", "MotionBlur:Transform" ); openGeometryObject(); addGeometry(gdp, 0.0f); while ( !m_renderer->m_motionTimes.empty() ) { setPreTransform( convert< UT_Matrix4T<float> >(m_renderer->m_motionTransforms.front()), m_renderer->m_motionTimes.front() ); m_renderer->m_motionTimes.pop_front(); m_renderer->m_motionTransforms.pop_front(); } applySettings(); closeObject(); m_renderer->m_motionType = RendererImplementation::Unknown; } else if ( m_renderer->m_motionType == RendererImplementation::Velocity ) { msg(Msg::Debug, "IECoreMantra::ProceduralPrimitive::addVisibleRenderable", "MotionBlur:Velocity" ); openGeometryObject(); addGeometry(gdp, 0.0f); addVelocityBlurGeometry(gdp, m_preBlur, m_postBlur); applySettings(); closeObject(); m_renderer->m_motionType = RendererImplementation::Unknown; } else { msg(Msg::Debug, "IECoreMantra::ProceduralPrimitive::addVisibleRenderable", "MotionBlur:None" ); openGeometryObject(); addGeometry( gdp, 0.0f ); setPreTransform( convert< UT_Matrix4T<float> >(m_renderer->m_transformStack.top()), 0.0f); applySettings(); closeObject(); } }
bool ToHoudiniGroupConverter::doConversion( const VisibleRenderable *renderable, GU_Detail *geo ) const { const Group *group = IECore::runTimeCast<const Group>( renderable ); if ( !group ) { return false; } Imath::M44f transform = ( runTimeCast<const M44fData>( m_transformParameter->getValue() ) )->readable(); const Transform *groupTransform = group->getTransform(); if ( groupTransform ) { transform = transform * groupTransform->transform(); } TransformOpPtr transformOp = new TransformOp(); M44fDataPtr transformData = new M44fData( transform ); transformOp->matrixParameter()->setValue( transformData ); std::string groupName = nameParameter()->getTypedValue(); if ( groupName == "" ) { // backwards compatibility with older data if ( const StringData *groupNameData = group->blindData()->member<StringData>( "name" ) ) { groupName = groupNameData->readable(); } } const std::string &attribFilter = attributeFilterParameter()->getTypedValue(); bool convertStandardAttributes = convertStandardAttributesParameter()->getTypedValue(); size_t i = 0; const Group::ChildContainer &children = group->children(); for ( Group::ChildContainer::const_iterator it=children.begin(); it != children.end(); ++it, ++i ) { ConstVisibleRenderablePtr child = *it; ConstPrimitivePtr primitive = runTimeCast<const Primitive>( child ); if ( primitive ) { transformOp->inputParameter()->setValue( constPointerCast<Primitive>( primitive ) ); child = staticPointerCast<VisibleRenderable>( transformOp->operate() ); } ToHoudiniGeometryConverterPtr converter = ToHoudiniGeometryConverter::create( child ); if ( !converter ) { continue; } std::string name = groupName; if ( const StringData *childNameData = child->blindData()->member<StringData>( "name" ) ) { const std::string &childName = childNameData->readable(); if ( childName != "" ) { if ( groupName != "" ) { name += "/"; } name += childName; } } converter->nameParameter()->setTypedValue( name ); converter->attributeFilterParameter()->setTypedValue( attribFilter ); converter->convertStandardAttributesParameter()->setTypedValue( convertStandardAttributes ); ToHoudiniGroupConverter *groupConverter = runTimeCast<ToHoudiniGroupConverter>( converter ); if ( groupConverter ) { groupConverter->transformParameter()->setValue( transformData ); } GU_DetailHandle handle; handle.allocateAndSet( geo, false ); if ( !converter->convert( handle ) ) { continue; } } return true; }