Seems I’m not following your “stack”
You are trying to reconstruct the unwelded mesh?
I called unweld right before:
for uv in lbw_mesh.uvs:
mesh.TextureCoordinates.Add(Rhino.Geometry.Point2f(uv[0], uv[1]))
Here is “clean” code which I have:
#! python3
import rhinoscriptsyntax as rs
import scriptcontext as sc
import math
import System
import System.Collections.Generic
import Rhino
# import the laubwerk module
import laubwerk
try:
# load a laubwerk plant file
lbw_plant = laubwerk.load("C:\path\to\Laubwerk\Plants\Acer_campestre\Acer_campestre.lbw.gz")
except IOError:
#print ("Plant file is missing")
Rhino.RhinoApp.WriteLine("Plant file is missing")
else:
# pick a specific model from the plant file
lbw_model = lbw_plant.models[0]
# generate the actual tree geometry
lbw_mesh = lbw_model.get_mesh(qualifier="summer", max_branch_level=1, min_thickness=0.3, leaf_amount=0.1, leaf_density=0.1, max_subdiv_level=1)
print("Created LBW_MESH. It has poly: " + str(len(lbw_mesh.polygons)) + " and verts: " + str(len(lbw_mesh.points)) + " and normals: " + str(len(lbw_mesh.normals)) + " and uvs: " + str(len(lbw_mesh.uvs)) + " and texverts: " + str(len(lbw_mesh.texverts)))
mesh = Rhino.Geometry.Mesh();
for pt in lbw_mesh.points:
mesh.Vertices.Add(pt[0],pt[1],pt[2])
for poly in lbw_mesh.polygons:
if len(poly) == 3:
mesh.Faces.AddFace(poly[0],poly[1],poly[2])
elif len(poly) == 4:
mesh.Faces.AddFace(poly[0],poly[1],poly[2],poly[3])
else:
print("Other poly not supported")
for nrm in lbw_mesh.normals:
mesh.Normals.Add(nrm[0],nrm[1],nrm[2])
#Unweld to match uvs Count
mesh.Unweld(0, False)
# Clear existing texture coordinates if any
mesh.TextureCoordinates.Clear()
for uv in lbw_mesh.uvs:
mesh.TextureCoordinates.Add(Rhino.Geometry.Point2f(uv[0], uv[1]))
#Change Y-Up to Z-Up
mesh.Rotate(math.radians(90),Rhino.Geometry.Vector3d(1,0,0),Rhino.Geometry.Point3d.Origin)
y, l = mesh.IsValidWithLog()
print(y, l)
print("Script executed sucessfully.")
print(sc.doc.Objects.AddMesh(mesh))
sc.doc.Views.Redraw()
At first glance I discarded texverts (probably due to the Thicket source reference), however, now I see texverts are ids of uvs per face which can possibly reverse to mesh polygons [A,B,C] or [A,B,C,D] so here is the possible way of getting back the unwelded thing… If my assumptions are correct…