Meshing SubD and adjusting meshing parameters programmatically

I’m working on a plugin for Rhino 7, and currently implementing meshing of SubDs.

When meshing a SubD with the meshing parameter dialog enabled, there is a level parameter slider. According to the docs this affects the level of detail in the resulting mesh, and can have a value between 1 and 5. However, I am not finding a way to access this property from code, unlike all the other meshing parameters in the dialog. I’m aware of SetSubDDisplayParameters() but it only seems to contain other specific properties of the SubD (e.g. MeshLocation and AdaptiveDisplayDensity) rather than a simple 1-5 value. Is there some mapping between these that I am not finding, or some other way of changing the 1-5 slider value?


Here is the relevant code for creating a mesh from the SubD. Note that subduiStyle = 1 is only for debugging and testing purposes. My goal is to have the settings dealt with programmatically without making the user select them manually for every SubD.

public static Mesh[] GetMeshFromSubD(RhinoObject rObj)
	Mesh[] subdMeshes;
	ObjectAttributes[] subdObjectAttribs;
	var subdMeshingParams = MeshingParameters.FastRenderMesh;
	
	var subduiStyle = 1; // -1 to hide dialog, 0 for simple slider, 1 for detailed meshing options
	var subdxform = Transform.Identity;

	// make rObj an enumerable of one object and mesh
	IEnumerable<RhinoObject> subdrObjEnumerable = Enumerable.Repeat(rObj, 1);
	var subdResult = RhinoObject.MeshObjects(
	    subdrObjEnumerable,
	    ref subdMeshingParams,
	    ref subduiStyle,
	    subdxform,
	    out subdMeshes,
	    out subdObjectAttribs
	);
	return subdMeshes;
}

Any help is greatly appreciated!

Hi @Wallace_Scott,

Something like this should do it.

var mp = MeshingParameters.FastRenderMesh;
var density = SubDDisplayParameters.ClampDisplayDensity((uint)some_value);
mp.SetSubDDisplayParameters(SubDDisplayParameters.CreateFromAbsoluteDisplayDensity(density));

– Dale

1 Like

Yes, thank you Dale! This solves the problem.