//Write out a binary file void Serialize::writeXMLtagfile() { hkOstream stream("geometry_xml_tagfile.xml"); hkResult res = hkSerializeUtil::saveTagfile(geometry, hkGeometryClass, stream.getStreamWriter(), HK_NULL, hkSerializeUtil::SAVE_TEXT_FORMAT); if (res != HK_SUCCESS) { HK_ERROR(0x000FF, "Failed to save binary"); } else { HK_WARN_ALWAYS(0x111AA, "Saved successfully"); } }
void hctConvertToPhantomActionFilter::setOptions(const void* optionData, int optionDataSize, unsigned int version ) { // Get the options from the XML data. if ( hctFilterUtils::readOptionsXml( optionData, optionDataSize, m_optionsBuf, hctConvertToPhantomActionOptionsClass ) == HK_SUCCESS ) { hctConvertToPhantomActionOptions* options = reinterpret_cast<hctConvertToPhantomActionOptions*>( m_optionsBuf.begin() ); m_options.m_removeMeshes = options->m_removeMeshes; } else { HK_WARN_ALWAYS( 0xabba482b, "The XML for the " << g_convertToPhantomActionDesc.getShortName() << " option data could not be loaded." ); return; } }
hkpWorld* FileManager::loadWorld( hkpPhysicsData** physicsData, hkResource** memData ) { hkIstream infile( SCRATCH_FILE ); HK_ASSERT( 0x215d080c, infile.isOk() ); *physicsData = hkpHavokSnapshot::load(infile.getStreamReader(), memData); if ( ! *physicsData ) { HK_WARN_ALWAYS(0x3e65b887, "Failed to load asset " << SCRATCH_FILE); return HK_NULL; } // Ensure non-multi threaded simulation for non-multi threaded platforms #if !defined(HK_PLATFORM_MULTI_THREAD) || (HK_CONFIG_THREAD == HK_CONFIG_SINGLE_THREADED) (*physicsData)->getWorldCinfo()->m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS; #endif hkpWorld* w = (*physicsData)->createWorld(); return w; }
//Read back a serialized file void Serialize::readBack() { hkIstream stream("geometry_xml_tagfile.xml"); hkResource* resource = hkSerializeUtil::load(stream.getStreamReader()); hkBool32 failed = true; if (resource) { //Get the contained Geometry hkGeometry* readGeometry = resource->getContents<hkGeometry>(); //Check to see if the last vertex is the same, as a simple check to //see if the serialization has worked correctly. failed = !readGeometry->m_vertices[7].equals3(readGeometry->m_vertices[7]); resource->removeReference(); } if (failed) { HK_ERROR(0x000FF, "Failed loading binary"); } else { HK_WARN_ALWAYS(0x111AA, "Loaded successfully"); } }
void updatePackfileDataVersion(hkArray<char>& ioBuf) { hkArray<char> origBuf; origBuf.swap(ioBuf); // Load the entire file inplace hkBinaryPackfileReader reader; reader.loadEntireFileInplace(origBuf.begin(), origBuf.getSize()); // check versioning if( hkVersionUtil::updateToCurrentVersion( reader, hkVersionRegistry::getInstance() ) != HK_SUCCESS ) { HK_WARN_ALWAYS(0, "Couldn't update version, skipping.\n"); } // Get the top level object in the file hkRootLevelContainer* container = static_cast<hkRootLevelContainer*>( reader.getContents( hkRootLevelContainerClass.getName() ) ); HK_ASSERT2(0xa6451543, container != HK_NULL, "Could not load root level obejct" ); hkOstream nativeFile(ioBuf); hkBool success = hkpHavokSnapshot::save(container, hkRootLevelContainerClass, nativeFile.getStreamWriter(), true); HK_ASSERT(0xa6451545, success == true); }
void MemoryInitUtil::runHk() { HK_WARN_ALWAYS(0x47625fd12, "Hello World!"); }
void hctConvertToPhantomActionFilter::process( hkRootLevelContainer& data ) { // Find and hkxScene and a hkPhysics Data objects in the root level container hkxScene* scenePtr = reinterpret_cast<hkxScene*>( data.findObjectByType( hkxSceneClass.getName() ) ); if (scenePtr == HK_NULL || (scenePtr->m_rootNode == HK_NULL) ) { HK_WARN_ALWAYS(0xabbaa5f0, "No scene data (or scene data root hkxNode) found. Can't continue."); return; } hkpPhysicsData* physicsPtr = reinterpret_cast<hkpPhysicsData*>( data.findObjectByType( hkpPhysicsDataClass.getName() ) ); if (physicsPtr == HK_NULL) { HK_WARN_ALWAYS(0xabbaa3d0, "No physics data found, you need to use Create Rigid Bodies before this filter or have bodies already in the input data."); return; } // Keep track of how many phantoms we created so we can reported int numConverted = 0; // Search for rigid bodies in the scene for (int psi=0; psi<physicsPtr->getPhysicsSystems().getSize(); psi++) { const hkpPhysicsSystem* psystem = physicsPtr->getPhysicsSystems()[psi]; for (int rbi=0; rbi<psystem->getRigidBodies().getSize(); rbi++) { hkpRigidBody* rbody = psystem->getRigidBodies()[rbi]; const char* rbName = rbody->getName(); // Require an associated node in the scene hkxNode* rbNode = (rbName)? scenePtr->findNodeByName(rbName): HK_NULL; if( !rbNode ) { continue; } // Require an 'hkPhantomAction' attribute group const hkxAttributeGroup* attrGroup = rbNode->findAttributeGroupByName("hkPhantomAction"); if (!attrGroup) { continue; } // Create our phantom shape MyPhantomShape* myPhantomShape = new MyPhantomShape(); { // Set action type (required) const char* actionTypeStr = HK_NULL; attrGroup->getStringValue( "action", true, actionTypeStr ); if( actionTypeStr ) { if( hkString::strCasecmp( actionTypeStr, "wind" ) == 0 ) { myPhantomShape->m_actionType = MyPhantomShape::ACTION_WIND; } else if( hkString::strCasecmp( actionTypeStr, "attract" ) == 0 ) { myPhantomShape->m_actionType = MyPhantomShape::ACTION_ATTRACT; } else if( hkString::strCasecmp( actionTypeStr, "deflect" ) == 0 ) { myPhantomShape->m_actionType = MyPhantomShape::ACTION_DEFLECT; } else { HK_WARN_ALWAYS(0xabbad3b4, "Unknow action type ("<<actionTypeStr<<")."); } } else { HK_WARN_ALWAYS(0xabba9834, "Can't fine \"action\" attribute"); } // Set other attributes (optional) attrGroup->getVectorValue( "direction", false, myPhantomShape->m_direction ); attrGroup->getFloatValue( "strength", false, myPhantomShape->m_strength ); // Useful warnings if ((myPhantomShape->m_actionType == MyPhantomShape::ACTION_WIND) && (myPhantomShape->m_direction.lengthSquared3()==0.0f)) { HK_WARN_ALWAYS(0xabbadf82, "Wind direction is invalid - action will have no effect"); } if (myPhantomShape->m_strength==0.0f) { HK_WARN_ALWAYS(0xabbacc83, "Strength is 0 - action will have no effect"); } } // Set the phantom as a new bounding shape for the body { const hkpShape* oldShape = rbody->getCollidable()->getShape(); hkpBvShape* bvShape = new hkpBvShape( oldShape, myPhantomShape ); myPhantomShape->removeReference(); rbody->setShape( bvShape ); bvShape->removeReference(); } // Remove meshes if the user chose to do so if (m_options.m_removeMeshes && (hkString::strCmp(rbNode->m_object.getClass()->getName(), "hkxMesh")==0) ) { rbNode->m_object = HK_NULL; } HK_REPORT("Converted rigid body \""<<rbName<<"\" to phantom action"); numConverted++; } } // Give a warning if the filter didn't do anything useful if (numConverted==0) { HK_WARN_ALWAYS(0xabba7632, "No rigid bodies converted to phantom action."); } else { HK_REPORT("Converted "<<numConverted<<" rigid bodies."); } }