@@ -433,12 +433,12 @@ cdef class Model:
433433 return ExternalModel._get(str (filename))
434434
435435 @staticmethod
436- cdef Model _vector(Vector vertices, Vector faces):
437- return VectorModel._get(vertices, faces)
436+ cdef Model _vector(Vector vertices, Vector faces, Vector uv ):
437+ return VectorModel._get(vertices, faces, uv )
438438
439439 @staticmethod
440- def vector (vertices , faces = None ):
441- return VectorModel._get(Vector._coerce(vertices), Vector._coerce(faces))
440+ def vector (vertices , faces = None , uv = None ):
441+ return VectorModel._get(Vector._coerce(vertices), Vector._coerce(faces), Vector._coerce(uv) )
442442
443443 @staticmethod
444444 cdef Model _sdf(Function function, Model original, Vector minimum, Vector maximum, double resolution):
@@ -1615,24 +1615,30 @@ cdef class ExternalModel(Model):
16151615cdef class VectorModel(Model):
16161616 cdef Vector vertices
16171617 cdef Vector faces
1618+ cdef Vector uv
16181619
16191620 @staticmethod
1620- cdef VectorModel _get(Vector vertices, Vector faces):
1621+ cdef VectorModel _get(Vector vertices, Vector faces, Vector uv ):
16211622 if vertices is None or vertices.numbers == NULL :
16221623 return None
16231624 if faces is not None and faces.numbers == NULL :
16241625 faces = None
1626+ if uv is not None and uv.numbers == NULL :
1627+ uv = None
16251628 cdef uint64_t id = VECTOR
16261629 id = HASH_UPDATE(id , vertices.hash(False ))
16271630 if faces is not None :
16281631 id = HASH_UPDATE(id , faces.hash(False ))
1632+ if uv is not None :
1633+ id = HASH_UPDATE(id , uv.hash(False ))
16291634 cdef VectorModel model
16301635 cdef PyObject* objptr = PyDict_GetItem(ModelCache, id )
16311636 if objptr == NULL :
16321637 model = VectorModel.__new__ (VectorModel)
16331638 model.id = id
16341639 model.vertices = vertices
16351640 model.faces = faces
1641+ model.uv = uv
16361642 ModelCache[id ] = model
16371643 else :
16381644 model = < VectorModel> objptr
@@ -1641,9 +1647,13 @@ cdef class VectorModel(Model):
16411647
16421648 @property
16431649 def name (self ):
1650+ cdef str name = f' vector({self.vertices.hash(False):x}'
16441651 if self .faces is not None :
1645- return f' vector({self.vertices.hash(False):x}, {self.faces.hash(False):x})'
1646- return f' vector({self.vertices.hash(False):x})'
1652+ name += f' , faces={self.faces.hash(False):x}'
1653+ if self .uv is not None :
1654+ name += f' , uv={self.uv.hash(False):x}'
1655+ name += ' )'
1656+ return name
16471657
16481658 cpdef void check_for_changes(self ):
16491659 pass
@@ -1678,6 +1688,13 @@ cdef class VectorModel(Model):
16781688 vertices[i, 0 ] = < float > self .vertices.numbers[i* 3 ]
16791689 vertices[i, 1 ] = < float > self .vertices.numbers[i* 3 + 1 ]
16801690 vertices[i, 2 ] = < float > self .vertices.numbers[i* 3 + 2 ]
1691+ if self .uv is not None :
1692+ if self .uv.length != n* 2 :
1693+ logger.error(" Bad uv vector length: {}" , self .name)
1694+ return None
1695+ for i in range (n):
1696+ vertices[i, 6 ] = < float > self .uv.numbers[i* 2 ]
1697+ vertices[i, 7 ] = < float > self .uv.numbers[i* 2 + 1 ]
16811698 if self .faces is None :
16821699 points = trimesh.points.PointCloud(vertices = vertices_array[:, :3 ]).convex_hull
16831700 faces_array = np.array(points.faces, dtype = ' i4' )
0 commit comments