New Subd Crease API throws errors between 4.0 and 5.0

C# SubDEdgeSharpness API throws errors.gh (76.8 KB)

Hi McNeel team,

First of all, a huge thanks to the developers for exposing the SubD crease functionality in RhinoCommon (RH-79547) in Rhino 8 SR36 RC!

I have been testing the new SubDEdge.Sharpness API and the SubDEdgeSharpness struct inside a Grasshopper C# component, and I’ve noticed some interesting behavior regarding the input values.

When applying sharpness values to the edges of a closed SubD, I observed the following:

  • When the sharpness value reaches 4.01, the C# component throws an error (turns red).

  • When the value reaches 5.0, it works perfectly, and the SubD edge becomes extremely sharp (essentially a hard crease).

  • When the value goes beyond 5.0, the code throws an error again.

I am trying to understand the underlying logic here. Are these errors caused by my C# implementation, topological limitations (e.g., OpenSubdiv calculation issues with specific decimal weights on closed meshes), or is it a limitation/bug within the newly exposed API itself?

Is the valid effective range strictly meant to be clamped between 0.0 and 5.0? Any insights on how to handle these values safely would be greatly appreciated!

Thanks in advance,
Quan

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{
    private void RunScript(
		DataTree<SubD> S,
		DataTree<int> E,
		DataTree<double> W,
		ref object A)
    {
        DataTree<SubD> outTree = new DataTree<SubD>();

        for (int i = 0; i < S.BranchCount; i++)
        {
            GH_Path path = S.Path(i);
            List<SubD> subdList = S.Branch(path);

            List<int> edgeIndices = E.PathExists(path) ? E.Branch(path) : (E.BranchCount > 0 ? E.Branch(0) : new List<int>());
            List<double> edgeWeights = W.PathExists(path) ? W.Branch(path) : (W.BranchCount > 0 ? W.Branch(0) : new List<double>());

            for (int j = 0; j < subdList.Count; j++)
            {
                SubD originalSubD = subdList[j];
                
                if (originalSubD == null)
                {
                    outTree.Add(null, path);
                    continue;
                }

                SubD dupSubD = (SubD)originalSubD.Duplicate();
                
                for(int k = 0; k < edgeIndices.Count; k++)
                {
                    int eIdx = edgeIndices[k];
                    
                    double w = k < edgeWeights.Count ? edgeWeights[k] : (edgeWeights.Count > 0 ? edgeWeights[edgeWeights.Count - 1] : 0.0);
                    
                    SubDEdge edge = dupSubD.Edges.Find(eIdx);
                    if (edge != null)
                    {
                        if (w <= 0.0)
                        {
                            edge.Sharpness = SubDEdgeSharpness.Smooth;
                        }
                        else
                        {
                            // 【解除注释,真正执行赋值】
                            // 由于我们无法完全确定 SR36 暴露的这个结构体的实例化方法名,
                            // 这里提供最标准的 C# 实例化写法。
                            // 如果你在新版编辑器里点击 Run 后这里报红字,
                            // 请删掉等号后面的代码,输入 SubDEdgeSharpness. 
                            // 然后在弹出的代码提示列表中,选择那个带有 Weight/Percentage 之类字眼的方法。
                            edge.Sharpness = new SubDEdgeSharpness(w); 
                        }
                    }
                }
                
                outTree.Add(dupSubD, path);
            }
        }
        
        A = outTree;
    }
}

Hi, @dale @pierrec
Seems like 5.0 is the upper limit of the crease, but why crease between 4.0 to 5.0 is not controllable? Is this a bug or…?

Honeycam 2026-10-19 15-32-46

Hi @Quan_Li ,

SubDEdgeSharpness(double sharpness) takes a double between 0.0 and SubDEdgeSharpness.MaximumValue (which is 4.0), or it also accepts SubDEdgeSharpness.CreaseValue (which is 5.0).

Anything between 0.0 and SubDEdgeSharpness.MaximumValue creates a SubD “soft crease” like the SubDCrease command would do. 0.0 maps to a SubDCrease percentage of 0% (which is a regular smooth edge), and MaximumValue maps to a SubDCrease percentage of 100% (which is the maximum value Rhino will accept for a SubD soft crease).

SubDEdgeSharpness.CreaseValue will create a SubD creased edge, like the Crease command would do. This value is accepted as a convenience to be able to create both soft creases and hard creases from the same functions (and to make creating the official Grasshopper components that will use these functions easier).

Got it, thank you very much!

This is an updated code.
If the crease value is larger than 4.0, it will be seen as 5.0.

using System;
using System.Collections;
using System.Collections.Generic;

using Rhino;
using Rhino.Geometry;

using Grasshopper;
using Grasshopper.Kernel;
using Grasshopper.Kernel.Data;
using Grasshopper.Kernel.Types;

public class Script_Instance : GH_ScriptInstance
{
    private void RunScript(DataTree<SubD> S, DataTree<int> E, DataTree<double> W, ref object A)
    {
        // -------------------------------------------------------------
        // 基于 McNeel 工程师回复优化的 SubD Edge Crease API (RH-79547)
        // -------------------------------------------------------------
        
        DataTree<SubD> outTree = new DataTree<SubD>();

        for (int i = 0; i < S.BranchCount; i++)
        {
            GH_Path path = S.Path(i);
            List<SubD> subdList = S.Branch(path);

            List<int> edgeIndices = E.PathExists(path) ? E.Branch(path) : (E.BranchCount > 0 ? E.Branch(0) : new List<int>());
            List<double> edgeWeights = W.PathExists(path) ? W.Branch(path) : (W.BranchCount > 0 ? W.Branch(0) : new List<double>());

            for (int j = 0; j < subdList.Count; j++)
            {
                SubD originalSubD = subdList[j];
                
                if (originalSubD == null)
                {
                    outTree.Add(null, path);
                    continue;
                }

                SubD dupSubD = (SubD)originalSubD.Duplicate();
                
                for(int k = 0; k < edgeIndices.Count; k++)
                {
                    int eIdx = edgeIndices[k];
                    double w = k < edgeWeights.Count ? edgeWeights[k] : (edgeWeights.Count > 0 ? edgeWeights[edgeWeights.Count - 1] : 0.0);
                    
                    SubDEdge edge = dupSubD.Edges.Find(eIdx);
                    if (edge != null)
                    {
                        // ---------------------------------------------------------
                        // 核心逻辑更新:基于官方 API 限制进行阈值控制
                        // ---------------------------------------------------------
                        if (w <= 0.0)
                        {
                            // 权重为 0 或负数,恢复完全平滑
                            edge.Sharpness = SubDEdgeSharpness.Smooth;
                        }
                        else if (w > 0.0 && w <= 4.0)
                        {
                            // 软倒角范围 (0.0 到 4.0)
                            // 对应 Rhino UI 中的 0% 到 100% SubDCrease
                            edge.Sharpness = new SubDEdgeSharpness(w);
                        }
                        else
                        {
                            // 大于 4.0 的值,一律映射为 5.0 (绝对硬边)
                            // 根据工程师的说法,这对应 SubDEdgeSharpness.CreaseValue
                            edge.Sharpness = new SubDEdgeSharpness(5.0); 
                        }
                    }
                }
                
                outTree.Add(dupSubD, path);
            }
        }
        
        A = outTree;
    }
}

I’d suggest something like this instead, so you do not depend on hardcoded values that could change in the future:

if (w <= SubDEdgeSharpness.SmoothValue)
{
    edge.Sharpness = SubDEdgeSharpness.Smooth;
}
else if (w <= SubDEdgeSharpness.MaximumValue)
{
    edge.Sharpness = new SubDEdgeSharpness(w);
}
else
{
    edge.Sharpness = SubDEdgeSharpness.Crease; 
}

Or even better, since you seem to be trying to reproduce the SubDCrease behavior, and probably want the slider to be in a normalized range like [0; 1] or [0%; 100%], you could use:

edge.Sharpness == SharpnessFromSliderValue(Interval(0, 1), w, SubDEdgeSharpness.CreaseValue)

That would make anything outside the [0; 1] range into a crease.

Or have a look at the many other methods like FromConstantPercentage

Hi @pierrec
Thank you for the clarification on SubDEdgeSharpness! It works perfectly for edges. However, in the native Rhino SubDCrease command, we can also select a Vertex and assign a percentage crease weight to it directly (creating a vertex dart/cone).
I searched the 8.36 API but couldn’t find a SubDVertexSharpness struct or a CreaseWeight property for SubDVertex. Is the soft crease API for vertices not exposed yet, or does it use a different naming convention?

You’ll need to use a non-constant SubDEdgeSharpness for that. SubD vertices don’t have a crease weight attached to them, it’s only the edges that can carry that property. When the UI shows you changing the weight of a vertex, what it’s actually doing is changing the weight of the end of the currently active edges that end at that vertex.