Surface parameters from meshing

Hi,

I have to mesh a trimmed NURBS surface (1) and need the surface parameters of each vertex (2). This can be done via the Mesh.CreateFromBrep and Surface.ClosestPoint operation. However, this is very time-consuming for larger models.

Is there a way that Mesh.CreateFromBrep already emits the parameter position? I guess this information should be available during the meshing process.

This feature would be very useful for isogeometric analysis and especially postprocessing. This could then be done directly in Rhino.

Best
Thomas

Hi Thomas,

How about creating the mesh with “UnpackedUnscaledNormalized” TextureRange:

This quick python setup shows how to setup the TextureRange to reflect the normalized surface parameters.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

obj_id = rs.SelectedObjects()
brep = rs.coercebrep(obj_id)

# MeshingParameters and Mesh creation
text_range = Rhino.Geometry.MeshingParameterTextureRange.UnpackedUnscaledNormalized
meshing_parms = Rhino.Geometry.MeshingParameters()  
meshing_parms.TextureRange = text_range 

mesh = Rhino.Geometry.Mesh.CreateFromBrep(brep, meshing_parms)[0]


# retrieve and test texture coordinates against surface parameters
texture_coords = mesh.TextureCoordinates
verts =  mesh.Vertices

surface = brep.Faces[0].UnderlyingSurface()
dom_u = surface.Domain(0)
dom_v = surface.Domain(1)

for i in range(verts.Count):
    # get normalized texturecoordinate
    tex_u, tex_v = texture_coords[i]
    # reconstruct surface parms
    s_u = dom_u.ParameterAt(tex_u)
    s_v = dom_v.ParameterAt(tex_v)
    
    # test by closestpoint evaluation
    rc, u, v = surface.ClosestPoint(verts[i])
    
    print '---'
    print s_u
    print u
    print '---'
    print s_v
    print v

output:

...
---
382.773772275
382.773768948
---
239.472391529
239.472379620
---
382.773772275
382.773777006
---
221.344451960
221.344443185
---
382.773772275
382.773774836
---
230.408410621
230.408416192
---
405.022589645
405.022594914
---
212.280471053
212.280471469
---
360.524954906
360.524965449
---
212.280471053
212.280468596
---
382.773772275
382.773772675
...

Hi Willem,

seems to be exactly what I was looking for. Thanks a lot!

1 Like