int main(int argc, char *argv[]) { // Make sure to install the GU plug-ins GU_Detail::loadIODSOs(); // Process command line arguments UT_Args args; args.initialize(argc, argv); args.stripOptions("l:o:v:h"); if (args.found('h')) { usage(argv[0]); return 1; } const char *output = args.found('o') ? args.argp('o') : "stdout.geo"; int lod = args.found('l') ? args.iargp('l') : 3; const char *viewportLOD = args.found('v') ? args.argp('v') : "full"; GU_Detail gdp; // Create a packed sphere primitive GU_PrimPacked *pack = GU_PrimPacked::build(gdp, "PackedSphere"); if (!pack) fprintf(stderr, "Can't create a packed sphere\n"); else { // Set the location of the packed primitive's point. UT_Vector3 pivot(0, 0, 0); pack->setPivot(pivot); gdp.setPos3(pack->getPointOffset(0), pivot); // Set the options on the sphere primitive UT_Options options; options.setOptionI("lod", lod); pack->implementation()->update(options); pack->setViewportLOD(GEOviewportLOD(viewportLOD)); // Save the geometry. With the .so file installed, this should load // into Houdini and should be rendered by mantra. if (!gdp.save(output, NULL).success()) fprintf(stderr, "Error saving to: %s\n", output); } return 0; }
bool GusdGU_PackedUSD::save(UT_Options &options, const GA_SaveMap &map) const { options.setOptionS( "usdFileName", m_fileName ); options.setOptionS( "usdAltFileName", m_altFileName ); options.setOptionS( "usdPrimPath", m_primPath.GetText() ); options.setOptionS( "usdSrcPrimPath", m_srcPrimPath.GetText() ); options.setOptionI( "usdIndex", m_index ); options.setOptionF( "usdFrame", GusdUSD_Utils::GetNumericTime(m_frame) ); UT_StringArray purposes; getIntrinsicPurposes( purposes ); options.setOptionSArray( "usdViewportPurpose", purposes ); return true; }
void RATDeepImageWriter::open() { if ( m_outputFile && fileName() == m_outputFileName ) { // we already opened the right file successfully return; } delete m_outputFile; m_outputFile = new IMG_DeepShadow; m_outputFileName = ""; m_dataSize = 3; m_alphaOffset = -1; m_extraOffset = -1; const std::vector<std::string> &channelNames = m_channelsParameter->getTypedValue(); // use A if it exists, otherwise assume opaque std::vector<std::string>::const_iterator aIt = std::find( channelNames.begin(), channelNames.end(), "A" ); if ( aIt != channelNames.end() ) { m_alphaOffset = aIt - channelNames.begin(); } // add the extra channels, including color int numChannels = channelNames.size(); for ( int i=0; i < numChannels; ++i ) { std::string name = channelNames[i]; // must have RGBA in order to have color if ( ( name == "R" ) && ( i < numChannels - 3 ) && ( channelNames[i+1] == "G" ) && ( channelNames[i+2] == "B" ) && ( m_alphaOffset == i + 3 ) ) { // adding 3 to the actual offset since the opacity triple must come first m_outputFile->addExtraChannel( IMG_DeepShadowChannel( "C", i+3, 4 ) ); m_dataSize += 4; if ( m_extraOffset < 0 ) { m_extraOffset = i; } } else if ( name != "G" && name != "B" && name != "A" ) { // adding 3 to the actual offset since the opacity triple must come first m_outputFile->addExtraChannel( IMG_DeepShadowChannel( name.c_str(), i+3, 1 ) ); if ( m_extraOffset < 0 ) { m_extraOffset = i; } m_dataSize++; } } m_outputFile->setOption( "compositing", "0" ); m_outputFile->setOption( "depth_interp", "discrete" ); const Imath::V2i &resolution = m_resolutionParameter->getTypedValue(); if ( m_outputFile->open( fileName().c_str(), resolution.x, resolution.y ) ) { m_outputFileName = fileName(); // set the worldToCamera matrix UT_Options *options = m_outputFile->getTBFOptions(); options->setOptionM4( "space:world", IECore::convert<UT_Matrix4>( worldToCameraParameter()->getTypedValue() ) ); /// \todo: set the cameraToNDC parameters } else { delete m_outputFile; m_outputFile = 0; m_outputFileName = ""; m_dataSize = 3; m_alphaOffset = -1; m_extraOffset = -1; throw IOException( std::string( "Failed to open file \"" ) + fileName() + "\" for writing." ); } }
void GusdGU_PackedUSD::update(const UT_Options &options) { UT_StringHolder fileName, altFileName, primPath; if( options.importOption( "usdFileName", fileName ) || options.importOption( "fileName", fileName )) { m_fileName = fileName; } if( options.importOption( "usdAltFileName", altFileName ) || options.importOption( "altFileName", altFileName )) { setAltFileName( altFileName ); } if( options.importOption( "usdPrimPath", primPath ) || options.importOption( "nodePath", primPath )) { GusdUSD_Utils::CreateSdfPath(primPath, m_primPath); } if( options.importOption( "usdSrcPrimPath", primPath )) { GusdUSD_Utils::CreateSdfPath(primPath, m_srcPrimPath); } exint index; if( options.importOption( "usdIndex", index )) { m_index = index; } fpreal frame; if( options.importOption( "usdFrame", frame ) || options.importOption( "frame", frame )) { m_frame = frame; } UT_StringArray purposes; if( options.importOption( "usdViewportPurpose", purposes )) { setIntrinsicPurposes( purposes ); } resetCaches(); }
bool RATDeepImageReader::open( bool throwOnFailure ) { if ( m_inputFile && fileName() == m_inputFileName ) { // we already opened the right file successfully return true; } delete m_ratPixel; delete m_inputFile; m_inputFile = new IMG_DeepShadow; m_inputFileName = ""; m_channelNames = ""; m_ratPixel = 0; m_depthChannel = 0; m_opacityChannel = 0; m_colorChannel = 0; m_dataWindow.max.x = 0; m_dataWindow.max.y = 0; m_worldToCamera = Imath::M44f(); m_worldToNDC = Imath::M44f(); bool success = true; if ( m_inputFile->open( fileName().c_str() ) && m_inputFile->depthInterp() == IMG_COMPRESS_DISCRETE ) { m_inputFileName = fileName(); m_ratPixel = new IMG_DeepPixelReader( *m_inputFile ); const IMG_DeepShadowChannel *channel = 0; unsigned numChannels = m_inputFile->getChannelCount(); for ( unsigned c=0; c < numChannels; ++c ) { channel = m_inputFile->getChannel( c ); std::string name = channel->getName(); if ( name == "Pz" ) { m_depthChannel = channel; } else if ( name == "Of" ) { m_opacityChannel = channel; } else if ( name == "C" ) { m_colorChannel = channel; } } if ( m_colorChannel ) { m_channelNames = "RGBA"; } else { m_colorChannel = m_opacityChannel; m_channelNames = "A"; } if ( !m_depthChannel || !m_opacityChannel || !m_colorChannel ) { success = false; } m_inputFile->resolution( m_dataWindow.max.x, m_dataWindow.max.y ); m_dataWindow.max.x -= 1; m_dataWindow.max.y -= 1; UT_Matrix4 wToC( 1 ); m_inputFile->getWorldToCamera( wToC ); m_worldToCamera = IECore::convert<Imath::M44f>( wToC ); UT_Matrix4 wToNDC( 1 ); m_inputFile->getWorldToNDC( wToNDC, true ); // wToNDC has flipped values and a scaling issue related to the far clipping plane // applying a matrix that seems to fix the issues in several examples Imath::M44f fix; fix.makeIdentity(); UT_Options *options = m_inputFile->getTBFOptions(); if ( options->hasOption( "camera:clip" ) ) { const UT_Vector2D clip = options->getOptionV2( "camera:clip" ); fix[2][2] = clip[1]; fix[3][3] = -1; } m_worldToNDC = IECore::convert<Imath::M44f>( wToNDC ) * fix; } else { success = false; } if ( !success ) { delete m_ratPixel; delete m_inputFile; m_inputFile = 0; m_inputFileName = ""; m_channelNames = ""; m_ratPixel = 0; m_depthChannel = 0; m_opacityChannel = 0; m_colorChannel = 0; m_dataWindow.max.x = 0; m_dataWindow.max.y = 0; m_worldToCamera = Imath::M44f(); m_worldToNDC = Imath::M44f(); if ( !throwOnFailure ) { return false; } else { throw IOException( std::string( "Failed to open file \"" ) + fileName() + "\"" ); } } return true; }