From e1bf674c16e3c8472b29574159c789cd3f0c64e0 Mon Sep 17 00:00:00 2001 From: Bryan Galdrikian Date: Fri, 24 Feb 2017 09:32:20 -0800 Subject: Updating to blast_source-windows@1.0.347-21749006 and blast_tools_and_samples-windows@1.0.347-21749006 with a new directory structure. NvBlast folder is gone, files have been moved to top level directory. README is changed to reflect this. --- docs/api_docs/files/pagellapi.html | 266 +++++++++++++++++++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 docs/api_docs/files/pagellapi.html (limited to 'docs/api_docs/files/pagellapi.html') diff --git a/docs/api_docs/files/pagellapi.html b/docs/api_docs/files/pagellapi.html new file mode 100644 index 0000000..1748161 --- /dev/null +++ b/docs/api_docs/files/pagellapi.html @@ -0,0 +1,266 @@ + + + NVIDIA(R) Blast(R) SDK 1.0 API Reference: Low Level API (NvBlast) + + + + + + + +
+

Low Level API (NvBlast)

Table of Contents

+Introduction

+Linking and Header Files

+Creating an Asset from a Descriptor (Authoring)

+Creating Actors and Families

+Damage and Fracturing

+
+

+Introduction

+The low-level API is the core of Blast™ destruction. It is designed to be a minimal API that allows an experienced user to incorporate destruction into their application. Summarizing what the low-level API has, or rather doesn't have:

+

+

+
+

+Linking and Header Files

+To use the low-level Blast™ SDK, the application need only inlclude the header NvBlast.h, found in the top-level include folder, and link against the appropriate version of the NvBlast library. Depending on the platform and configuration, various suffixes will be added to the library name. The general naming scheme is

+NvBlast(config)(arch).(ext)

+(config) is DEBUG, CHECKED, OR PROFILE for the corresponding configurations. For a release configuration there is no (config) suffix.

+(arch) is _x86 or _x64 for Windows 32- and 64-bit builds, respectively, and empty for non-Windows platforms.

+(ext) is .lib for static linking and .dll for dynamic linking on Windows. On XBoxOne it is .lib, and on PS4 it is .a.

+
+

+Creating an Asset from a Descriptor (Authoring)

+The NvBlastAsset is an opaque type pointing to an object constructed by Blast™ in memory allocated by the user. To create an asset from a descriptor, use the function NvBlastAssetCreate. See the function documentation for a description of its parameters.

+N.B., there are strict rules for the ordering of chunks with an asset, and also conditions on the chunks marked as "support" (using the NvBlastChunkDesc::SupportFlag). See the function documentation for these conditions. NvBlastAssetCreate does not reorder chunks or modify support flags to meet these conditions. If the conditions are not met, NvBlastAssetCreate fails and returns NULL. However, Blast™ provides helper functions to reorder chunk descriptors and modify the support flags within those descriptors so that they are valid for asset creation. The helper functions return a mapping from the original chunk ordering to the new chunk ordering, so that corresponding adjustments or mappings may be made for graphics and other data the user associates with chunks.

+Example code is given below.

+

std::vector<NvBlastChunkDesc> chunkDescs;
+chunkDescs.resize( chunkCount );    // chunkCount > 0
+
+chunkDescs[0].parentChunkIndex = UINT32_MAX;    // invalid index denotes a chunk hierarchy root
+chunkDescs[0].centroid[0] = 0.f;    // centroid position in asset-local space
+chunkDescs[0].centroid[1] = 0.f;
+chunkDescs[0].centroid[2] = 0.f;
+chunkDescs[0].volume = 1.f; // Unit volume
+chunkDescs[0].flags = NvBlastChunkDesc::NoFlags;
+chunkDescs[0].ID = 0;   // User-supplied ID.  For example, this can be the index of the chunkDesc.
+                        // The ID can be left undefined.
+
+chunkDescs[1].parentChunkIndex = 0; // child of chunk described by chunkDescs[0]
+chunkDescs[1].centroid[0] = 2.f;    // centroid position in asset-local space
+chunkDescs[1].centroid[1] = 4.f;
+chunkDescs[1].centroid[2] = 6.f;
+chunkDescs[1].volume = 1.0; // Unit volume
+chunkDescs[1].flags = NvBlastChunkDesc::SupportFlag; // This chunk should be represented in the support graph
+chunkDescs[1].ID = 1;
+
+// ... etc.
+
+std::vector<NvBlastBondDesc> bondDescs;
+bondDescs.resize( bondCount );  // bondCount > 0
+
+bondDescs[0].chunkIndices[0] = 1;   // chunkIndices refer to chunk descriptor indices for support chunks
+bondDescs[0].chunkIndices[1] = 2;
+bondDescs[0].bond.m_normal[0] = 1.f;    // normal in the +x direction
+bondDescs[0].bond.m_normal[1] = 0.f;
+bondDescs[0].bond.m_normal[2] = 0.f;
+bondDescs[0].bond.m_area = 1.0; // unit area
+bondDescs[0].bond.m_centroid[0] = 1.f;  // centroid position in asset-local space
+bondDescs[0].bond.m_centroid[1] = 2.f;
+bondDescs[0].bond.m_centroid[2] = 3.f;
+bondDescs[0].m_userData = 0;    // this can be used to tell the user more information about this
+                                // bond for example to create a joint when this bond breaks
+
+// ... etc.
+
+// Set the fields of the descriptor
+NvBlastAssetDesc assetDesc;
+assetDesc.chunkCount = chunkCount;
+assetDesc.chunkDescs = chunkDescs.data();
+assetDesc.bondCount = bondCount;
+assetDesc.bondDescs = bondDescs.data();
+
+// Now ensure the support coverage in the chunk descriptors is exact, and the chunks are correctly ordered
+std::vector<char> scratch( chunkCount * sizeof(NvBlastChunkDesc) ); // This is enough scratch for both NvBlastEnsureAssetExactSupportCoverage and NvBlastReorderAssetDescChunks
+NvBlastEnsureAssetExactSupportCoverage( chunkDescs.data(), chunkCount, scratch.data(), nullptr );
+std::vector<uint32_t> map(chunkCount);  // Will be filled with a map from the original chunk descriptor order to the new one
+NvBlastReorderAssetDescChunks( chunkDescs.data(), chunkDescs, bondDescs.data(), bondCount, map, scratch.data(), nullptr );
+
+// Create the asset
+scratch.resize( NvBlastGetRequiredScratchForCreateAsset( &assetDesc ) );    // Provide scratch memory for asset creation
+void* mem = malloc( NvBlastGetAssetMemorySize( &assetDesc ) );      // Allocate memory for the asset object
+NvBlastAsset* asset = NvBlastCreateAsset( mem, &assetDesc, scratch.data(), nullptr );   // the log function (last argument) is optional
+

+
+ It should be noted that the geometric information (centroid, volume, area, normal) in chunks and bonds is only used by damage shader functions (see Damage Shaders (NvBlastExtShaders)). Depending on the shader, some, all, or none of the geometric information will be needed. The user may write damage shader functions that interpret this data in any way they wish.

+
+

+Cloning an Asset (Serialization and Deserialization)

+To clone an asset, or equivalently serialize and deserialize it (as long as the deserialized asset is being created on a host with the same data version and endianness), one only needs to copy the memory associated with the NvBlastAsset.

+

uint32_t assetSize = NvBlastAssetGetSize( data );
+
+NvBlastAsset* newAsset = (NvBlastAsset*)malloc(assetSize);  // NOTE: the memory buffer <em> must <\em> be 16-byte aligned!
+memcpy( newAsset, asset, assetSize );   // this data may be copied into a buffer, stored to a file, etc.
+

+N.B. the comment after the malloc call above. NvBlastAsset memory must be 16-byte aligned.

+
+

+Releasing an Asset

+Blast&tm low-level does no internal allocation; since the memory is allocated by the user, one simply has to free the memory they've allocated. The asset pointer returned by NvBlastCreateAsset has the same numerical value as the mem block passed in (if the function is successful, or NULL otherwise). So releasing an asset done as follows:

+

free( asset );
+

+
+

+Creating Actors and Families

+Actors live within a family created from asset data. To create an actor, one must first create a family. This family is used by the initial actor created from the asset, as well as all of the descendent actors created by recursively fracturing the initial actor. Like assets, family allocation is done by the user.

+To create a family, use:

+

// Allocate memory for the family object - this depends on the asset being represented by the family.
+void* mem = malloc( NvBlastAssetGetFamilyMemorySize( &asset ) );
+
+NvBlastFamily* family = NvBlastAssetCreateFamily( mem, &asset, nullptr );
+

+When an actor is first created from an asset, it represents the root of the chunk hierarchy, that is the unfractured object. To create this actor, use:

+

// Set the fields of the descriptor
+NvBlastActorDesc actorDesc;
+actorDesc.asset = asset;    // point to a valid asset
+actorDesc.initialBondHealth = 1.0f;  // this health value will be given to all bonds
+actorDesc.initialChunkHealth = 1.0f; // this health value will be given to all lower-support chunks
+
+// Provide scratch memory
+std::vector<char> scratch( NvBlastFamilyGetRequiredScratchForCreateFirstActor( &actorDesc ) );
+
+// Create the first actor
+NvBlastActor* actor = NvBlastFamilyCreateFirstActor( family, &actorDesc, scratch.data(), nullptr ); // ready to be associated with physics and graphics by the user
+

+
+

+Copying Actors (Serialization and Deserialization)

+There are two forms of serialization: family serialization and single actor serialization. Family serialization is extremely fast as it only requires a single memory copy. All actors in the family may be saved, loaded, or copied at once in this way.

+
+

+Family Serialization

+To serialize a family, use the family pointer which may be retrieved from any active actor in the family if needed, using the NvBlastActorGetFamily function:

+

const NvBlastFamily* family = NvBlastActorGetFamily( &actor, nullptr );
+

+Then the size of the family may be obtained using:

+

size_t size = NvBlastFamilyGetSize( family, nullptr );
+

+Now this memory may be copied, saved to disk, etc. To clone the family, for example, we can duplicate the memory:

+

std::vector<char> buffer( size );
+NvBlastFamily* family2 = reinterpret_cast<NvBlastFamily*>( buffer.data() );
+memcpy( family2, family, size );
+

+N.B. If this data has been serialized from an external source, the family will not contain a valid reference to its associated asset. The user must set the family's asset. The family does however contain the asset's GUID, to help the user match the correct asset to the family. So one way of restoring the asset to the family follows:

+

const NvBlastGUID guid = NvBlastFamilyGetAssetGUID( family2, nullptr );
+// ... here the user must retrieve the asset using the GUID or by some other means
+NvBlastFamilySetAsset( family2, asset, nullptr );
+

+The data in family2 will contain the same actors as the original family. To access them, use:

+

uint32_t actorCount = NvBlastFamilyGetActorCount( family2, nullptr );
+std::vector<NvBlastActor*> actors( actorCount );
+uint32_t actorsWritten = NvBlastFamilyGetActors( actors.data(), actorCount, family2, nullptr );
+

+In the code above, actorsWritten should equal actorCount.

+
+

+Single Actor Serialization

+To perform single-actor serialization, first find the buffer size required to store the serialization data:

+

size_t bufferSize = NvBlastActorGetSerializationSize( actor, nullptr );
+

+If you want to use an upper bound which will be large enough for any actor in a family, you may use:

+

size_t bufferSize = NvBlastAssetGetActorSerializationSizeUpperBound( asset, nullptr );
+

+Then create a buffer of that size and use NvBlastActorSerialize to write to the buffer:

+

std::vector<char> buffer( bufferSize );
+size_t bytesWritten = NvBlastActorSerialize( buffer, bufferSize, actor, nullptr );
+

+To deserialize the buffer, an appropriate family must be created. It must not already hold a copy of the actor. It must be formed using the correct asset (the one that originally created the actor):

+

NvBlastFamily* family = NvBlastAssetCreateFamily( asset, malloc, nullptr );
+

+Then deserialize into the family:

+

NvBlastActor* newActor = NvBlastFamilyDeserializeActor( family, buffer.data(), nullptr );
+

+If newActor is not NULL, then the actor was successfully deserialized.

+
+

+Deactivating an Actor

+Actors may not be released in the usual sense of deallocation. This is because actors' memory is stored as a block within the owning family. The memory is only released when the family is released. However, one may deactivate an actor using NvBlastActorDeactivate. This clears the actor's chunk lists and marks it as invalid, effectively disassociating it from the family. The user should consider this actor to be destroyed.

+

bool success = NvBlastActorDeactivate( actor ); // actor should always be a pointer, as it is an opaque type
+

+
+

+Releasing a family

+As mentioned above, releasing an actor does not actually do any deallocation; it simply invalidates the actor within its family. To actually deallocate memory, you must deallocate the family. Note, this will invalidate all actors in the family. This is a fast way to delete all actors that were created from repeated fracturing of a single instance. As with NvBlastAsse, memory is allocated by the user, so to release the family simply free that memory:

+

free( family );
+

+The family will not be automatically released when all actors within it are invalidated using NvBlastActorDeactivate. However, the user may keep track of the number of active actors in a family using

+

uint32_t actorCount = NvBlastFamilyGetActorCount( family, nullptr );
+

+The result of the call above, actually a reference count for the family, is accurate even if actors are created and deleted from different threads.

+
+

+Damage and Fracturing

+Damaging and fracturing is a staged process. In a first step, a NvBlastDamageProgram creates lists of Bonds and Chunks to damage - so called Fracture Commands. The lists are created from input specific to the NvBlastDamageProgram.
+ NvBlastDamagePrograms are composed of a NvBlastGraphShaderFunction and a NvBlastSubgraphShaderFunction operating on support graphs (support chunks and bonds) and disconnected subsupport chunks respectively. An implementer can freely define the shader functions and paramters. Different functions can have the effect of emulating different physical materials.
+ Blast™ provides example implementations of such functions in Damage Shaders (NvBlastExtShaders), see also NvBlastExtDamageShaders.h. The NvBlastDamageProgram is used through NvBlastActorGenerateFracture that will provide the necessary internal data for the NvBlastActor being processed. The shader functions see the internal data as NvBlastGraphShaderActor and NvBlastSubgraphShaderActor respectively.

+The second stage is carried out with NvBlastActorApplyFracture. This function takes the previously generated Fracture Commands and applies them to the NvBlastActor. The result of every applied command is reported as a respective Fracture Event if requested.

+Fracture Commands and Fracture Events both are represented by NvBlastFractureBuffers. The splitting of the actor into child actors is not done until the third stage, NvBlastActorSplit, is called. Fractures may be repeatedly applied to an actor before splitting.

+The NvBlastActorGenerateFracture, NvBlastActorApplyFracture and NvBlastActorSplit functions are profiled in Profile configurations. This is done through a pointer to a NvBlastTimers struct passed into the functions. If this pointer is not NULL, then timing values will be accumulated in the referenced struct.

+The following example illustrates the process:

+

// Step one: Generate Fracture Commands
+
+// Damage programs (shader functions), material properties and damage description relate to each other.
+// Together they define how actors will break by generating the desired set of Fracture Commands for Bonds and Chunks.
+NvBlastDamageProgram damageProgram = { GraphShader, SubgraphShader };
+NvBlastProgramParams programParams = { damageDescs, damageDescCount, materialProperties };
+
+// Generating the set of Fracture Commands does not modify the NvBlastActor.
+NvBlastActorGenerateFracture(fractureCommands, actor, damageProgram, &programParams, logFn, &timers);
+
+
+// Step two: Apply Fracture Commands
+
+// Applying Fracture Commands does modify the state of the NvBlastActor.
+// The Fracture Events report the resulting state of each Bond or Chunk involved.
+// Chunks fractured hard enough will also fracture their children, creating Fracture Events for each.
+NvBlastActorApplyFracture(fractureEvents, actor, fractureCommands, logFn, &timers);
+
+
+// Step three: Splitting
+
+// The Actor may be split into all its smallest pieces.
+uint32_t maxNewActorCount = NvBlastActorSplitMaxActorCount(actor);
+std::vector<NvBlastActor*> newActors(maxNewActorCount);
+
+// Make this memory available to NvBlastSplitEvent.
+NvBlastActorSplitEvent splitEvent;
+splitEvent.newActors = newActors.data();
+
+// Some temporary memory is necessary as well.
+std::vector<char> scratch(NvBlastActorGetRequiredScratchForSplit(actor));
+
+// New actors created are reported in splitEvent.newActors.
+// If newActorCount != 0, then the old actor is deleted and is reported in splitEvent.deletedActor.
+size_t newActorCount = NvBlastActorSplit(&splitEvent, actor, maxNewActorCount, scratch.data(), logFn, &timers);
+

+
+

+ + + + -- cgit v1.2.3