From 4bced2d73f61b440f81b3dff68e66cad5787d64d Mon Sep 17 00:00:00 2001 From: "WISH\\AndyBuchanan" Date: Tue, 14 Aug 2018 16:06:02 +0100 Subject: Fixes to UnitySample to make it build & run. ( In Unity 2018.2 ) --- .../Plugins/Blast/NvBlastExtShadersWrapper.cs | 27 ++--- .../Assets/Plugins/Blast/NvBlastExtUtilsWrapper.cs | 32 +++-- .../Assets/Plugins/Blast/NvBlastWrapper.cs | 135 ++++++++++++--------- .../Assets/Plugins/Blast/x64/NvBlastDEBUG_x64.dll | Bin 239616 -> 260608 bytes .../Blast/x64/NvBlastExtAssetUtilsDEBUG_x64.dll | Bin 0 -> 69632 bytes .../x64/NvBlastExtAssetUtilsDEBUG_x64.dll.meta | 24 ++++ .../Plugins/Blast/x64/NvBlastExtAssetUtils_x64.dll | Bin 0 -> 19456 bytes .../Blast/x64/NvBlastExtAssetUtils_x64.dll.meta | 24 ++++ .../Blast/x64/NvBlastExtCommonDEBUG_x64.dll | Bin 54272 -> 0 bytes .../Blast/x64/NvBlastExtCommonDEBUG_x64.dll.meta | 54 --------- .../Blast/x64/NvBlastExtShadersDEBUG_x64.dll | Bin 61952 -> 131072 bytes .../Plugins/Blast/x64/NvBlastExtShaders_x64.dll | Bin 0 -> 40448 bytes .../Blast/x64/NvBlastExtShaders_x64.dll.meta | 24 ++++ .../Plugins/Blast/x64/NvBlastExtUtilsDEBUG_x64.dll | Bin 99328 -> 0 bytes .../Blast/x64/NvBlastExtUtilsDEBUG_x64.dll.meta | 54 --------- .../Plugins/Blast/x64/NvBlastGlobalsDEBUG_x64.dll | Bin 0 -> 101376 bytes .../Blast/x64/NvBlastGlobalsDEBUG_x64.dll.meta | 24 ++++ .../Plugins/Blast/x64/NvBlastGlobals_x64.dll | Bin 0 -> 12800 bytes .../Plugins/Blast/x64/NvBlastGlobals_x64.dll.meta | 24 ++++ .../Assets/Plugins/Blast/x64/NvBlast_x64.dll | Bin 0 -> 64512 bytes .../Assets/Plugins/Blast/x64/NvBlast_x64.dll.meta | 24 ++++ examples/UnityExample/Assets/Scripts/CubeFamily.cs | 35 ++++-- examples/UnityExample/Assets/Scripts/Demo.cs | 4 +- 23 files changed, 285 insertions(+), 200 deletions(-) create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtAssetUtilsDEBUG_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtAssetUtilsDEBUG_x64.dll.meta create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtAssetUtils_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtAssetUtils_x64.dll.meta delete mode 100755 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtCommonDEBUG_x64.dll delete mode 100755 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtCommonDEBUG_x64.dll.meta create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtShaders_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtShaders_x64.dll.meta delete mode 100755 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtUtilsDEBUG_x64.dll delete mode 100755 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastExtUtilsDEBUG_x64.dll.meta create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastGlobalsDEBUG_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastGlobalsDEBUG_x64.dll.meta create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastGlobals_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlastGlobals_x64.dll.meta create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlast_x64.dll create mode 100644 examples/UnityExample/Assets/Plugins/Blast/x64/NvBlast_x64.dll.meta (limited to 'examples/UnityExample/Assets') diff --git a/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtShadersWrapper.cs b/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtShadersWrapper.cs index 21e208c..7b4c5d1 100755 --- a/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtShadersWrapper.cs +++ b/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtShadersWrapper.cs @@ -7,36 +7,33 @@ using UnityEngine; [StructLayout(LayoutKind.Sequential)] public class NvBlastExtRadialDamageDesc { - public float compressive; //!< compressive (radial) damage component + public float damage; //!< normalized damage amount, range: [0, 1] (maximum health value to be reduced) public float p0; public float p1; public float p2; - public float minRadius; //!< inner radius of damage action + public float minRadius; //!< inner radius of damage action public float maxRadius; //!< outer radius of damage action }; [StructLayout(LayoutKind.Sequential)] public class NvBlastExtMaterial { - public float singleChunkThreshold; //!< subsupport chunks only take damage surpassing this value - public float graphChunkThreshold; //!< support chunks only take damage surpassing this value - public float bondTangentialThreshold; //!< bond only take damage surpassing this value - public float bondNormalThreshold; //!< currently unused - forward damage propagation - public float damageAttenuation; //!< factor of damage attenuation while forwarding + public float health; //!< health + public float minDamageThreshold; //!< min damage fraction threshold to be applied. Range [0, 1]. For example 0.1 filters all damage below 10% of health. + public float maxDamageThreshold; //!< max damage fraction threshold to be applied. Range [0, 1]. For example 0.8 won't allow more then 80% of health damage to be applied. }; - public static class NvBlastExtShadersWrapper { public const string DLL_NAME = "NvBlastExtShaders" + NvBlastWrapper.DLL_POSTFIX + "_" + NvBlastWrapper.DLL_PLATFORM; #region Dll [DllImport(DLL_NAME)] - private static extern bool NvBlastExtDamageActorRadialFalloff(IntPtr actor, NvBlastFractureBuffers buffers, NvBlastExtRadialDamageDesc damageDescBuffer, UInt32 damageDescCount, NvBlastExtMaterial material, NvBlastWrapper.NvBlastLog logFn, NvBlastTimers timers); - #endregion + public static extern void NvBlastExtFalloffGraphShader( NvBlastFractureBuffers buffers, NvBlastGraphShaderActor actor, NvBlastExtProgramParams p ); // System.IntPtr xparams + + [DllImport(DLL_NAME)] + public static extern void NvBlastExtFalloffSubgraphShader( NvBlastFractureBuffers buffers, NvBlastSubgraphShaderActor actor, NvBlastExtProgramParams p ); // NvBlastExtProgramParams + #endregion + +} - public static bool DamageRadialFalloff(this NvBlastActor actor, NvBlastFractureBuffers buffers, NvBlastExtRadialDamageDesc damageDescBuffer, UInt32 damageDescCount, NvBlastExtMaterial material) - { - return NvBlastExtDamageActorRadialFalloff(actor.ptr, buffers, damageDescBuffer, damageDescCount, material, NvBlastWrapper.Log, null); - } -} \ No newline at end of file diff --git a/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtUtilsWrapper.cs b/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtUtilsWrapper.cs index 94ca399..c902192 100755 --- a/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtUtilsWrapper.cs +++ b/examples/UnityExample/Assets/Plugins/Blast/NvBlastExtUtilsWrapper.cs @@ -7,15 +7,29 @@ using UnityEngine; public static class NvBlastExtUtilsWrapper { - public const string DLL_NAME = "NvBlastExtUtils" + NvBlastWrapper.DLL_POSTFIX + "_" + NvBlastWrapper.DLL_PLATFORM; + //!AJB 20180809 Function was moved to a different plug in + public const string DLL_NAME = "NvBlast" + NvBlastWrapper.DLL_POSTFIX + "_" + NvBlastWrapper.DLL_PLATFORM; // NvBlastExtAssetUtils - #region Dll - [DllImport(DLL_NAME)] - private static extern void NvBlastReorderAssetDescChunks([In, Out] NvBlastChunkDesc[] chunkDescs, uint chunkCount, [In, Out] NvBlastBondDesc[] bondDescs, uint bondCount, [In, Out] uint[] chunkReorderMap); - #endregion + #region Dll + [DllImport(DLL_NAME)] + private static extern void NvBlastReorderAssetDescChunks + ( + [In, Out] NvBlastChunkDesc[] chunkDescs, + UInt32 chunkCount, + [In, Out] NvBlastBondDesc[] bondDescs, + UInt32 bondCount, + UInt32[] chunkReorderMap, + bool keepBondNormalChunkOrder, + System.IntPtr scratch, + System.UIntPtr logFn // NvBlastLog, may be null + ); + #endregion - public static void ReorderAssetDescChunks(NvBlastAssetDesc assetDesc, uint[] chunkReorderMap) + public static void ReorderAssetDescChunks(NvBlastAssetDesc assetDesc, uint[] chunkReorderMap) { - NvBlastReorderAssetDescChunks(assetDesc.chunkDescs, assetDesc.chunkCount, assetDesc.bondDescs, assetDesc.bondCount, chunkReorderMap); - } -} \ No newline at end of file + System.IntPtr scratchPtr = NvBlastWrapper.GetScratch( (int)( assetDesc.chunkCount * Marshal.SizeOf( typeof(NvBlastChunkDesc) ) ) ); + NvBlastReorderAssetDescChunks(assetDesc.chunkDescs, assetDesc.chunkCount, assetDesc.bondDescs, assetDesc.bondCount, chunkReorderMap, true, scratchPtr, System.UIntPtr.Zero); + } +} + + diff --git a/examples/UnityExample/Assets/Plugins/Blast/NvBlastWrapper.cs b/examples/UnityExample/Assets/Plugins/Blast/NvBlastWrapper.cs index 13822f8..41b4f68 100755 --- a/examples/UnityExample/Assets/Plugins/Blast/NvBlastWrapper.cs +++ b/examples/UnityExample/Assets/Plugins/Blast/NvBlastWrapper.cs @@ -13,8 +13,8 @@ public struct NvBlastChunkDesc SupportFlag = (1 << 0) }; - /** Central position in chunk. */ - public Single c0; + /** Central position in chunk. */ + public Single c0; public Single c1; public Single c2; @@ -49,12 +49,12 @@ public struct NvBlastBond public struct NvBlastBondDesc { - /** The indices of the chunks linked by this bond. They must be different support chunk indices. */ - public UInt32 chunk0; - public UInt32 chunk1; + /** Bond data (see NvBlastBond). */ + public NvBlastBond bond; - /** Bond data (see NvBlastBond). */ - public NvBlastBond bond; + /** The indices of the chunks linked by this bond. They must be different support chunk indices. */ + public UInt32 chunk0; + public UInt32 chunk1; } [StructLayout(LayoutKind.Sequential)] @@ -137,7 +137,8 @@ public struct NvBlastChunk public UInt32 userData; }; -public struct NvBlastChunkGraph + +public struct NvBlastSupportGraph { UInt32 nodeCount; public IntPtr chunkIndices; @@ -189,28 +190,34 @@ public class NvBlastFractureBuffers public class NvBlastActorSplitEvent { public IntPtr deletedActor; //!< deleted actor or nullptr if actor has not changed - public IntPtr newActors; //!< list of created actors + public IntPtr newActors; //!< list of created actors ( NvBlastActor** ) }; [StructLayout(LayoutKind.Sequential)] public class NvBlastGraphShaderActor { - UInt32 firstGraphNodeIndex; //("CubePrefab"); @@ -39,7 +39,7 @@ public class CubeFamily : MonoBehaviour actorDesc.uniformInitialBondHealth = 1.0f; actorDesc.uniformInitialLowerSupportChunkHealth = 1.0f; var actor = new NvBlastActor(_blastFamily, actorDesc); - Debug.Log(actor.visibleChunkCount); +// Debug.Log(actor.visibleChunkCount); OnActorCreated(actor, Vector3.zero, Quaternion.identity); @@ -126,7 +126,7 @@ public class CubeFamily : MonoBehaviour return false; } - private void ApplyRadialDamage(NvBlastActor actor, Vector3 localPosition, float minRadius, float maxRadius, float compressive) + private void ApplyRadialDamage( NvBlastActor actor, Vector3 localPosition, float minRadius, float maxRadius, float compressive ) { _fractureBuffers.chunkFractureCount = _cubeAsset.solverAssetDesc.chunkCount; _fractureBuffers.bondFractureCount = _cubeAsset.solverAssetDesc.bondCount; @@ -134,18 +134,35 @@ public class CubeFamily : MonoBehaviour NvBlastExtRadialDamageDesc desc = new NvBlastExtRadialDamageDesc(); desc.minRadius = minRadius; desc.maxRadius = maxRadius; - desc.compressive = compressive; + desc.damage = compressive; desc.p0 = localPosition.x; desc.p1 = localPosition.y; desc.p2 = localPosition.z; - if (actor.DamageRadialFalloff(_fractureBuffers, desc, 1, null)) - { - Split(actor); - } + IntPtr dam = Marshal.AllocHGlobal( Marshal.SizeOf( typeof(NvBlastExtRadialDamageDesc) ) ); + Marshal.StructureToPtr( desc, dam, false ); + + var damP = new NvBlastDamageProgram() { + graphShaderFunction = NvBlastExtShadersWrapper.NvBlastExtFalloffGraphShader, + subgraphShaderFunction = NvBlastExtShadersWrapper.NvBlastExtFalloffSubgraphShader + }; + var programParams = new NvBlastExtProgramParams() { + damageDescBuffer = dam, + material = IntPtr.Zero, + accelerator = IntPtr.Zero + }; + + actor.GenerateFracture( _fractureBuffers, damP, programParams ); + actor.ApplyFracture( _fractureBuffers ); + if ( _fractureBuffers.bondFractureCount + _fractureBuffers.chunkFractureCount > 0 ) + { + Split( actor ); + } + + Marshal.FreeHGlobal(dam); } - private void Split(NvBlastActor actor) + private void Split( NvBlastActor actor ) { NvBlastActorSplitEvent split = new NvBlastActorSplitEvent(); split.newActors = _newActorsBuffer; diff --git a/examples/UnityExample/Assets/Scripts/Demo.cs b/examples/UnityExample/Assets/Scripts/Demo.cs index 725229e..cfb2570 100755 --- a/examples/UnityExample/Assets/Scripts/Demo.cs +++ b/examples/UnityExample/Assets/Scripts/Demo.cs @@ -8,7 +8,9 @@ public class Demo : MonoBehaviour void Awake () { - generateCity(); + //NativeLoader.Load(); + + generateCity(); } private void generateCity() -- cgit v1.2.3