private static VFXExpression GetParticleMass( InitializeSolver initializeBlock, VFXExpression h, VFXExpression mass, VFXExpression density) { if (initializeBlock?.AutomaticMass ?? true) { var hCubed = h * h * h; var hParticleFactor = VFXValue.Constant(FluvioFXSettings.kAutoParticleSizeFactor); return (VFXValue.Constant(4.0f / 3.0f) * VFXValue.Constant(Mathf.PI) * hCubed * hParticleFactor * density); } else { return(mass); } }
private static IEnumerable <VFXNamedExpression> GetExpressionsImpl( InitializeSolver initializeBlock, SolverDataParameters solverDataParams, IEnumerable <VFXNamedExpression> fluid, VFXExpression h, VFXExpression mass, VFXExpression density, VFXExpression gravity) { // Fluid if (fluid == null || h == null || mass == null || density == null) { var defaultFluid = Fluid.defaultValue; h = VFXValue.Constant(defaultFluid.SmoothingDistance); if (solverDataParams.HasFlag(SolverDataParameters.Fluid_ParticleMass)) { yield return(new VFXNamedExpression( GetParticleMass( initializeBlock, h, VFXValue.Constant(defaultFluid.ParticleMass), VFXValue.Constant(defaultFluid.Density) ), "solverData_Fluid_ParticleMass")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_Density)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.Density), "solverData_Fluid_Density")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_MinimumDensity)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.MinimumDensity), "solverData_Fluid_MinimumDensity")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_GasConstant)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.GasConstant), "solverData_Fluid_GasConstant")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_Viscosity)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.Viscosity), "solverData_Fluid_Viscosity")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_SurfaceTension)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.SurfaceTension), "solverData_Fluid_SurfaceTension")); } if (solverDataParams.HasFlag(SolverDataParameters.Fluid_BuoyancyCoefficient)) { yield return(new VFXNamedExpression( VFXValue.Constant(defaultFluid.BuoyancyCoefficient), "solverData_Fluid_BuoyancyCoefficient")); } } else { foreach (var expression in fluid) { if (Enum.TryParse(expression.name, out SolverDataParameters solverDataParameter) && solverDataParams.HasFlag(solverDataParameter)) { if (solverDataParameter == SolverDataParameters.Fluid_ParticleMass) { yield return(new VFXNamedExpression( GetParticleMass(initializeBlock, h, mass, density), "solverData_Fluid_ParticleMass")); continue; } yield return(new VFXNamedExpression(expression.exp, $"solverData_{expression.name}")); } } ; } // KernelSize: x - h, y - h^2, z - h^3, w - h / 2 if (solverDataParams.HasFlag(SolverDataParameters.KernelSize)) { yield return(new VFXNamedExpression(new VFXExpressionCombine(new [] { h, h * h, h * h * h, h * VFXValue.Constant(0.5f), }), "solverData_KernelSize")); } // KernelFactors: x - poly6, y - spiky, z - viscosity if (solverDataParams.HasFlag(SolverDataParameters.KernelFactors)) { var poly6 = new Poly6Kernel(h); var spiky = new SpikyKernel(h); var viscosity = new ViscosityKernel(h); yield return(new VFXNamedExpression(new VFXExpressionCombine(new [] { poly6.GetFactor(), spiky.GetFactor(), viscosity.GetFactor() }), "solverData_KernelFactors")); } // Gravity if (solverDataParams.HasFlag(SolverDataParameters.Gravity)) { if (gravity == null) { gravity = new VFXExpressionCombine(new [] { VFXValue.Constant(0.0f), VFXValue.Constant(-9.81f), VFXValue.Constant(0.0f), }); } yield return(new VFXNamedExpression(gravity, "solverData_Gravity")); } }