diff --git a/Examples/Ex_SimulationSetup.cs b/Examples/Ex_SimulationSetup.cs index 6611994..d042dca 100644 --- a/Examples/Ex_SimulationSetup.cs +++ b/Examples/Ex_SimulationSetup.cs @@ -179,14 +179,19 @@ VectorField oInletField Library.oViewer().SetGroupVisible(10, false); + // Create a new scalar field, which contains the density of water + // at all voxels which are in the fluid domain (997 kg/m³) + ScalarField oFluidDensity = new(voxFluid, 997.0f); + OpenVdbFile oFile = new(); voxFluid.m_oMetadata.SetValue("Simulation.Material.Name", "Water"); voxFluid.m_oMetadata.SetValue("Simulation.Material.Type", "Liquid"); oFile.nAdd(voxFluid, "Simulation.FluidDomain"); - oFile.nAdd(voxManifold, "Simulation.SolidDomain"); - oFile.nAdd(oFlowSpeed, "Simulation.FlowSpeed"); + oFile.nAdd(voxManifold, "Simulation.SolidDomain"); + oFile.nAdd(oFlowSpeed, "Simulation.FlowSpeed"); + oFile.nAdd(oFluidDensity, "Simulation.FluidDensity"); string strVdbFile = Path.Combine(Utils.strDocumentsFolder(), "Sim.vdb"); oFile.SaveToFile(strVdbFile); diff --git a/PicoGK_ScalarField.cs b/PicoGK_ScalarField.cs index 7435202..18e2bcc 100644 --- a/PicoGK_ScalarField.cs +++ b/PicoGK_ScalarField.cs @@ -79,14 +79,25 @@ public ScalarField(in ScalarField oSource) /// /// Creates a scalar field from an existing voxel field - /// the scalar field contains the signed distance values + /// setting the voxels inside the object to the specified value /// of the voxels /// /// Voxels to create SDF from + /// Value to set the scalar field to" + /// The threshold of the signed distance field + /// to be used for the definition of "inside" - usually 0.5 is a good + /// value - the surface is at exactly 0 and a value of + /// 1.0 means you are 1 voxel outside from the surface. public ScalarField(Voxels oVoxels) : this(_hCreateFromVoxels(oVoxels.m_hThis)) { } + public ScalarField( Voxels oVoxels, + float fValue, + float fSdThreshold = 0.5f) + : this(_hBuildFromVoxels(oVoxels.m_hThis, fValue, fSdThreshold)) + {} + /// /// Sets the value at the specified position in mm /// When you set a value, the position gets "activated" diff --git a/PicoGK__Interop.cs b/PicoGK__Interop.cs index 32a26e5..67ccbe8 100644 --- a/PicoGK__Interop.cs +++ b/PicoGK__Interop.cs @@ -748,6 +748,9 @@ public partial class ScalarField : IDisposable [DllImport(Config.strPicoGKLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ScalarField_hCreateFromVoxels")] public static extern IntPtr _hCreateFromVoxels(IntPtr hVoxels); + [DllImport(Config.strPicoGKLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ScalarField_hBuildFromVoxels")] + public static extern IntPtr _hBuildFromVoxels(IntPtr hVoxels, float fScalarValue, float fSdThreshold); + [DllImport(Config.strPicoGKLib, CallingConvention = CallingConvention.Cdecl, EntryPoint = "ScalarField_bIsValid")] private static extern bool _bIsValid(IntPtr hThis);