_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q23200 | Arcball.next | train | def next(self, acceleration=0.0):
"""Continue rotation in direction of last drag."""
q = quaternion_slerp(self._qpre, self._qnow, 2.0 + acceleration, False)
self._qpre, self._qnow = self._qnow, q | python | {
"resource": ""
} |
q23201 | validate_polygon | train | def validate_polygon(obj):
"""
Make sure an input can be returned as a valid polygon.
Parameters
-------------
obj : shapely.geometry.Polygon, str (wkb), or (n, 2) float
Object which might be a polygon
Returns
------------
polygon : shapely.geometry.Polygon
Valid polygon ob... | python | {
"resource": ""
} |
q23202 | extrude_polygon | train | def extrude_polygon(polygon,
height,
**kwargs):
"""
Extrude a 2D shapely polygon into a 3D mesh
Parameters
----------
polygon : shapely.geometry.Polygon
2D geometry to extrude
height : float
Distance to extrude polygon along Z
**kwargs:
... | python | {
"resource": ""
} |
q23203 | extrude_triangulation | train | def extrude_triangulation(vertices,
faces,
height,
**kwargs):
"""
Turn a 2D triangulation into a watertight Trimesh.
Parameters
----------
vertices : (n, 2) float
2D vertices
faces : (m, 3) int
Triangle in... | python | {
"resource": ""
} |
q23204 | _polygon_to_kwargs | train | def _polygon_to_kwargs(polygon):
"""
Given a shapely polygon generate the data to pass to
the triangle mesh generator
Parameters
---------
polygon : Shapely.geometry.Polygon
Input geometry
Returns
--------
result : dict
Has keys: vertices, segments, holes
"""
i... | python | {
"resource": ""
} |
q23205 | icosahedron | train | def icosahedron():
"""
Create an icosahedron, a 20 faced polyhedron.
Returns
-------------
ico : trimesh.Trimesh
Icosahederon centered at the origin.
"""
t = (1.0 + 5.0**.5) / 2.0
vertices = [-1, t, 0, 1, t, 0, -1, -t, 0, 1, -t, 0, 0, -1, t, 0, 1, t,
0, -1, -t, 0, ... | python | {
"resource": ""
} |
q23206 | icosphere | train | def icosphere(subdivisions=3, radius=1.0, color=None):
"""
Create an isophere centered at the origin.
Parameters
----------
subdivisions : int
How many times to subdivide the mesh.
Note that the number of faces will grow as function of
4 ** subdivisions, so you probably want to ke... | python | {
"resource": ""
} |
q23207 | capsule | train | def capsule(height=1.0,
radius=1.0,
count=[32, 32]):
"""
Create a mesh of a capsule, or a cylinder with hemispheric ends.
Parameters
----------
height : float
Center to center distance of two spheres
radius : float
Radius of the cylinder and hemispheres
c... | python | {
"resource": ""
} |
q23208 | cylinder | train | def cylinder(radius=1.0,
height=1.0,
sections=32,
segment=None,
transform=None,
**kwargs):
"""
Create a mesh of a cylinder along Z centered at the origin.
Parameters
----------
radius : float
The radius of the cylinder
heigh... | python | {
"resource": ""
} |
q23209 | annulus | train | def annulus(r_min=1.0,
r_max=2.0,
height=1.0,
sections=32,
transform=None,
**kwargs):
"""
Create a mesh of an annular cylinder along Z,
centered at the origin.
Parameters
----------
r_min : float
The inner radius of the annular c... | python | {
"resource": ""
} |
q23210 | random_soup | train | def random_soup(face_count=100):
"""
Return random triangles as a Trimesh
Parameters
-----------
face_count : int
Number of faces desired in mesh
Returns
-----------
soup : trimesh.Trimesh
Geometry with face_count random faces
"""
vertices = np.random.random((face_c... | python | {
"resource": ""
} |
q23211 | axis | train | def axis(origin_size=0.04,
transform=None,
origin_color=None,
axis_radius=None,
axis_length=None):
"""
Return an XYZ axis marker as a Trimesh, which represents position
and orientation. If you set the origin size the other parameters
will be set relative to it.
... | python | {
"resource": ""
} |
q23212 | camera_marker | train | def camera_marker(camera,
marker_height=0.4,
origin_size=None):
"""
Create a visual marker for a camera object, including an axis and FOV.
Parameters
---------------
camera : trimesh.scene.Camera
Camera object with FOV and transform defined
marker_heigh... | python | {
"resource": ""
} |
q23213 | convex_hull | train | def convex_hull(obj, qhull_options='QbB Pp QJn'):
"""
Get a new Trimesh object representing the convex hull of the
current mesh, with proper normals and watertight.
Requires scipy >.12.
Arguments
--------
obj : Trimesh, or (n,3) float
Mesh or cartesian points
Returns
--------... | python | {
"resource": ""
} |
q23214 | adjacency_projections | train | def adjacency_projections(mesh):
"""
Test if a mesh is convex by projecting the vertices of
a triangle onto the normal of its adjacent face.
Parameters
----------
mesh : Trimesh
Input geometry
Returns
----------
projection : (len(mesh.face_adjacency),) float
Distance of... | python | {
"resource": ""
} |
q23215 | is_convex | train | def is_convex(mesh):
"""
Check if a mesh is convex.
Parameters
-----------
mesh : Trimesh
Input geometry
Returns
-----------
convex : bool
Was passed mesh convex or not
"""
# don't consider zero- area faces
nonzero = mesh.area_faces > tol.merge
# adjacencie... | python | {
"resource": ""
} |
q23216 | hull_points | train | def hull_points(obj, qhull_options='QbB Pp'):
"""
Try to extract a convex set of points from multiple input formats.
Parameters
---------
obj: Trimesh object
(n,d) points
(m,) Trimesh objects
Returns
--------
points: (o,d) convex set of points
"""
if hasattr(o... | python | {
"resource": ""
} |
q23217 | Entity.closed | train | def closed(self):
"""
If the first point is the same as the end point
the entity is closed
"""
closed = (len(self.points) > 2 and
self.points[0] == self.points[-1])
return closed | python | {
"resource": ""
} |
q23218 | Entity.length | train | def length(self, vertices):
"""
Return the total length of the entity.
Returns
---------
length: float, total length of entity
"""
length = ((np.diff(self.discrete(vertices),
axis=0)**2).sum(axis=1)**.5).sum()
return length | python | {
"resource": ""
} |
q23219 | Text.plot | train | def plot(self, vertices, show=False):
"""
Plot the text using matplotlib.
Parameters
--------------
vertices : (n, 2) float
Vertices in space
show : bool
If True, call plt.show()
"""
if vertices.shape[1] != 2:
raise ValueEr... | python | {
"resource": ""
} |
q23220 | Text.angle | train | def angle(self, vertices):
"""
If Text is 2D, get the rotation angle in radians.
Parameters
-----------
vertices : (n, 2) float
Vertices in space referenced by self.points
Returns
---------
angle : float
Rotation angle in radians
... | python | {
"resource": ""
} |
q23221 | Line.discrete | train | def discrete(self, vertices, scale=1.0):
"""
Discretize into a world- space path.
Parameters
------------
vertices: (n, dimension) float
Points in space
scale : float
Size of overall scene for numerical comparisons
Returns
-----------... | python | {
"resource": ""
} |
q23222 | Line.is_valid | train | def is_valid(self):
"""
Is the current entity valid.
Returns
-----------
valid : bool
Is the current entity well formed
"""
valid = np.any((self.points - self.points[0]) != 0)
return valid | python | {
"resource": ""
} |
q23223 | Line.explode | train | def explode(self):
"""
If the current Line entity consists of multiple line
break it up into n Line entities.
Returns
----------
exploded: (n,) Line entities
"""
points = np.column_stack((
self.points,
self.points)).ravel()[1:-1].r... | python | {
"resource": ""
} |
q23224 | Arc.discrete | train | def discrete(self, vertices, scale=1.0):
"""
Discretize the arc entity into line sections.
Parameters
------------
vertices : (n, dimension) float
Points in space
scale : float
Size of overall scene for numerical comparisons
Returns
... | python | {
"resource": ""
} |
q23225 | Arc.bounds | train | def bounds(self, vertices):
"""
Return the AABB of the arc entity.
Parameters
-----------
vertices: (n,dimension) float, vertices in space
Returns
-----------
bounds: (2, dimension) float, (min, max) coordinate of AABB
"""
if util.is_shap... | python | {
"resource": ""
} |
q23226 | Bezier.discrete | train | def discrete(self, vertices, scale=1.0, count=None):
"""
Discretize the Bezier curve.
Parameters
-------------
vertices : (n, 2) or (n, 3) float
Points in space
scale : float
Scale of overall drawings (for precision)
count : int
Numb... | python | {
"resource": ""
} |
q23227 | BSpline.discrete | train | def discrete(self, vertices, count=None, scale=1.0):
"""
Discretize the B-Spline curve.
Parameters
-------------
vertices : (n, 2) or (n, 3) float
Points in space
scale : float
Scale of overall drawings (for precision)
count : int
Nu... | python | {
"resource": ""
} |
q23228 | BSpline.to_dict | train | def to_dict(self):
"""
Returns a dictionary with all of the information
about the entity.
"""
return {'type': self.__class__.__name__,
'points': self.points.tolist(),
'knots': self.knots.tolist(),
'closed': self.closed} | python | {
"resource": ""
} |
q23229 | print_element | train | def print_element(element):
"""
Pretty- print an lxml.etree element.
Parameters
------------
element : etree element
"""
pretty = etree.tostring(
element, pretty_print=True).decode('utf-8')
print(pretty)
return pretty | python | {
"resource": ""
} |
q23230 | merge_vertices | train | def merge_vertices(mesh,
digits=None,
textured=True,
uv_digits=4):
"""
Removes duplicate vertices based on integer hashes of
each row.
Parameters
-------------
mesh : Trimesh object
Mesh to merge vertices on
digits : int
H... | python | {
"resource": ""
} |
q23231 | group | train | def group(values, min_len=0, max_len=np.inf):
"""
Return the indices of values that are identical
Parameters
----------
values: 1D array
min_len: int, the shortest group allowed
All groups will have len >= min_length
max_len: int, the longest group allowed
... | python | {
"resource": ""
} |
q23232 | hashable_rows | train | def hashable_rows(data, digits=None):
"""
We turn our array into integers based on the precision
given by digits and then put them in a hashable format.
Parameters
---------
data : (n, m) array
Input data
digits : int or None
How many digits to add to hash if data is floating po... | python | {
"resource": ""
} |
q23233 | unique_ordered | train | def unique_ordered(data):
"""
Returns the same as np.unique, but ordered as per the
first occurrence of the unique value in data.
Examples
---------
In [1]: a = [0, 3, 3, 4, 1, 3, 0, 3, 2, 1]
In [2]: np.unique(a)
Out[2]: array([0, 1, 2, 3, 4])
In [3]: trimesh.grouping.unique_order... | python | {
"resource": ""
} |
q23234 | unique_bincount | train | def unique_bincount(values,
minlength,
return_inverse=True):
"""
For arrays of integers find unique values using bin counting.
Roughly 10x faster for correct input than np.unique
Parameters
--------------
values : (n,) int
Values to find unique memb... | python | {
"resource": ""
} |
q23235 | merge_runs | train | def merge_runs(data, digits=None):
"""
Merge duplicate sequential values. This differs from unique_ordered
in that values can occur in multiple places in the sequence, but
only consecutive repeats are removed
Parameters
-----------
data: (n,) float or int
Returns
--------
merge... | python | {
"resource": ""
} |
q23236 | unique_float | train | def unique_float(data,
return_index=False,
return_inverse=False,
digits=None):
"""
Identical to the numpy.unique command, except evaluates floating point
numbers, using a specified number of digits.
If digits isn't specified, the library default TOL_ME... | python | {
"resource": ""
} |
q23237 | unique_value_in_row | train | def unique_value_in_row(data, unique=None):
"""
For a 2D array of integers find the position of a value in each
row which only occurs once. If there are more than one value per
row which occur once, the last one is returned.
Parameters
----------
data: (n,d) int
unique: (m) int, list ... | python | {
"resource": ""
} |
q23238 | boolean_rows | train | def boolean_rows(a, b, operation=np.intersect1d):
"""
Find the rows in two arrays which occur in both rows.
Parameters
---------
a: (n, d) int
Array with row vectors
b: (m, d) int
Array with row vectors
operation : function
Numpy boolean set operation function:
... | python | {
"resource": ""
} |
q23239 | group_vectors | train | def group_vectors(vectors,
angle=1e-4,
include_negative=False):
"""
Group vectors based on an angle tolerance, with the option to
include negative vectors.
Parameters
-----------
vectors : (n,3) float
Direction vector
angle : float
Group v... | python | {
"resource": ""
} |
q23240 | group_distance | train | def group_distance(values, distance):
"""
Find groups of points which have neighbours closer than radius,
where no two points in a group are farther than distance apart.
Parameters
---------
points : (n, d) float
Points of dimension d
distance : float
Max distance between ... | python | {
"resource": ""
} |
q23241 | clusters | train | def clusters(points, radius):
"""
Find clusters of points which have neighbours closer than radius
Parameters
---------
points : (n, d) float
Points of dimension d
radius : float
Max distance between points in a cluster
Returns
----------
groups : (m,) sequence of i... | python | {
"resource": ""
} |
q23242 | blocks | train | def blocks(data,
min_len=2,
max_len=np.inf,
digits=None,
only_nonzero=False):
"""
Given an array, find the indices of contiguous blocks
of equal values.
Parameters
---------
data: (n) array
min_len: int, the minimum length group to be returned
... | python | {
"resource": ""
} |
q23243 | group_min | train | def group_min(groups, data):
"""
Given a list of groups, find the minimum element of data within each group
Parameters
-----------
groups : (n,) sequence of (q,) int
Indexes of each group corresponding to each element in data
data : (m,)
The data that groups indexes reference
... | python | {
"resource": ""
} |
q23244 | minimum_nsphere | train | def minimum_nsphere(obj):
"""
Compute the minimum n- sphere for a mesh or a set of points.
Uses the fact that the minimum n- sphere will be centered at one of
the vertices of the furthest site voronoi diagram, which is n*log(n)
but should be pretty fast due to using the scipy/qhull implementations
... | python | {
"resource": ""
} |
q23245 | fit_nsphere | train | def fit_nsphere(points, prior=None):
"""
Fit an n-sphere to a set of points using least squares.
Parameters
---------
points : (n, d) float
Points in space
prior : (d,) float
Best guess for center of nsphere
Returns
---------
center : (d,) float
Location of center... | python | {
"resource": ""
} |
q23246 | is_nsphere | train | def is_nsphere(points):
"""
Check if a list of points is an nsphere.
Parameters
-----------
points : (n, dimension) float
Points in space
Returns
-----------
check : bool
True if input points are on an nsphere
"""
center, radius, error = fit_nsphere(points)
chec... | python | {
"resource": ""
} |
q23247 | contains_points | train | def contains_points(intersector,
points,
check_direction=None):
"""
Check if a mesh contains a set of points, using ray tests.
If the point is on the surface of the mesh, behavior is
undefined.
Parameters
---------
mesh: Trimesh object
points: (n... | python | {
"resource": ""
} |
q23248 | mesh_to_BVH | train | def mesh_to_BVH(mesh):
"""
Create a BVHModel object from a Trimesh object
Parameters
-----------
mesh : Trimesh
Input geometry
Returns
------------
bvh : fcl.BVHModel
BVH of input geometry
"""
bvh = fcl.BVHModel()
bvh.beginModel(num_tris_=len(mesh.faces),
... | python | {
"resource": ""
} |
q23249 | scene_to_collision | train | def scene_to_collision(scene):
"""
Create collision objects from a trimesh.Scene object.
Parameters
------------
scene : trimesh.Scene
Scene to create collision objects for
Returns
------------
manager : CollisionManager
CollisionManager for objects in scene
objects: {n... | python | {
"resource": ""
} |
q23250 | CollisionManager.add_object | train | def add_object(self,
name,
mesh,
transform=None):
"""
Add an object to the collision manager.
If an object with the given name is already in the manager,
replace it.
Parameters
----------
name : str
... | python | {
"resource": ""
} |
q23251 | CollisionManager.remove_object | train | def remove_object(self, name):
"""
Delete an object from the collision manager.
Parameters
----------
name : str
The identifier for the object
"""
if name in self._objs:
self._manager.unregisterObject(self._objs[name]['obj'])
sel... | python | {
"resource": ""
} |
q23252 | CollisionManager.set_transform | train | def set_transform(self, name, transform):
"""
Set the transform for one of the manager's objects.
This replaces the prior transform.
Parameters
----------
name : str
An identifier for the object already in the manager
transform : (4,4) float
A... | python | {
"resource": ""
} |
q23253 | CollisionManager.in_collision_single | train | def in_collision_single(self, mesh, transform=None,
return_names=False, return_data=False):
"""
Check a single object for collisions against all objects in the
manager.
Parameters
----------
mesh : Trimesh object
The geometry of the ... | python | {
"resource": ""
} |
q23254 | CollisionManager.in_collision_other | train | def in_collision_other(self, other_manager,
return_names=False, return_data=False):
"""
Check if any object from this manager collides with any object
from another manager.
Parameters
-------------------
other_manager : CollisionManager
... | python | {
"resource": ""
} |
q23255 | CollisionManager.min_distance_single | train | def min_distance_single(self,
mesh,
transform=None,
return_name=False,
return_data=False):
"""
Get the minimum distance between a single object and any
object in the manager.
... | python | {
"resource": ""
} |
q23256 | CollisionManager.min_distance_internal | train | def min_distance_internal(self, return_names=False, return_data=False):
"""
Get the minimum distance between any pair of objects in the manager.
Parameters
-------------
return_names : bool
If true, a 2-tuple is returned containing the names
of the closest ob... | python | {
"resource": ""
} |
q23257 | CollisionManager.min_distance_other | train | def min_distance_other(self, other_manager,
return_names=False, return_data=False):
"""
Get the minimum distance between any pair of objects,
one in each manager.
Parameters
----------
other_manager : CollisionManager
Another collisio... | python | {
"resource": ""
} |
q23258 | cylinder_inertia | train | def cylinder_inertia(mass, radius, height, transform=None):
"""
Return the inertia tensor of a cylinder.
Parameters
------------
mass : float
Mass of cylinder
radius : float
Radius of cylinder
height : float
Height of cylinder
transform : (4,4) float
Transformati... | python | {
"resource": ""
} |
q23259 | principal_axis | train | def principal_axis(inertia):
"""
Find the principal components and principal axis
of inertia from the inertia tensor.
Parameters
------------
inertia : (3,3) float
Inertia tensor
Returns
------------
components : (3,) float
Principal components of inertia
vectors : ... | python | {
"resource": ""
} |
q23260 | transform_inertia | train | def transform_inertia(transform, inertia_tensor):
"""
Transform an inertia tensor to a new frame.
More details in OCW PDF:
MIT16_07F09_Lec26.pdf
Parameters
------------
transform : (3, 3) or (4, 4) float
Transformation matrix
inertia_tensor : (3, 3) float
Inertia tensor
... | python | {
"resource": ""
} |
q23261 | autolight | train | def autolight(scene):
"""
Generate a list of lights for a scene that looks decent.
Parameters
--------------
scene : trimesh.Scene
Scene with geometry
Returns
--------------
lights : [Light]
List of light objects
transforms : (len(lights), 4, 4) float
Transformati... | python | {
"resource": ""
} |
q23262 | tracked_array | train | def tracked_array(array, dtype=None):
"""
Properly subclass a numpy ndarray to track changes.
Avoids some pitfalls of subclassing by forcing contiguous
arrays, and does a view into a TrackedArray.
Parameters
------------
array : array- like object
To be turned into a TrackedArray
... | python | {
"resource": ""
} |
q23263 | TrackedArray.md5 | train | def md5(self):
"""
Return an MD5 hash of the current array.
Returns
-----------
md5: str, hexadecimal MD5 of the array
"""
if self._modified_m or not hasattr(self, '_hashed_md5'):
if self.flags['C_CONTIGUOUS']:
hasher = hashlib.md5(sel... | python | {
"resource": ""
} |
q23264 | TrackedArray.crc | train | def crc(self):
"""
A zlib.crc32 or zlib.adler32 checksum
of the current data.
Returns
-----------
crc: int, checksum from zlib.crc32 or zlib.adler32
"""
if self._modified_c or not hasattr(self, '_hashed_crc'):
if self.flags['C_CONTIGUOUS']:
... | python | {
"resource": ""
} |
q23265 | TrackedArray._xxhash | train | def _xxhash(self):
"""
An xxhash.b64 hash of the array.
Returns
-------------
xx: int, xxhash.xxh64 hash of array.
"""
# repeat the bookkeeping to get a contiguous array inside
# the function to avoid additional function calls
# these functions ar... | python | {
"resource": ""
} |
q23266 | Cache.verify | train | def verify(self):
"""
Verify that the cached values are still for the same
value of id_function and delete all stored items if
the value of id_function has changed.
"""
# if we are in a lock don't check anything
if self._lock != 0:
return
# ch... | python | {
"resource": ""
} |
q23267 | Cache.clear | train | def clear(self, exclude=None):
"""
Remove all elements in the cache.
"""
if exclude is None:
self.cache = {}
else:
self.cache = {k: v for k, v in self.cache.items()
if k in exclude} | python | {
"resource": ""
} |
q23268 | DataStore.is_empty | train | def is_empty(self):
"""
Is the current DataStore empty or not.
Returns
----------
empty: bool, False if there are items in the DataStore
"""
if len(self.data) == 0:
return True
for v in self.data.values():
if is_sequence(v):
... | python | {
"resource": ""
} |
q23269 | DataStore.md5 | train | def md5(self):
"""
Get an MD5 reflecting everything in the DataStore.
Returns
----------
md5: str, MD5 in hexadecimal
"""
hasher = hashlib.md5()
for key in sorted(self.data.keys()):
hasher.update(self.data[key].md5().encode('utf-8'))
m... | python | {
"resource": ""
} |
q23270 | DataStore.crc | train | def crc(self):
"""
Get a CRC reflecting everything in the DataStore.
Returns
----------
crc: int, CRC of data
"""
crc = sum(i.crc() for i in self.data.values())
return crc | python | {
"resource": ""
} |
q23271 | DataStore.fast_hash | train | def fast_hash(self):
"""
Get a CRC32 or xxhash.xxh64 reflecting the DataStore.
Returns
------------
hashed: int, checksum of data
"""
fast = sum(i.fast_hash() for i in self.data.values())
return fast | python | {
"resource": ""
} |
q23272 | identifier_simple | train | def identifier_simple(mesh):
"""
Return a basic identifier for a mesh, consisting of properties
that have been hand tuned to be somewhat robust to rigid
transformations and different tesselations.
Parameters
----------
mesh : Trimesh object
Source geometry
Returns
----------
... | python | {
"resource": ""
} |
q23273 | identifier_hash | train | def identifier_hash(identifier, sigfig=None):
"""
Hash an identifier array to a specified number of
significant figures.
Parameters
----------
identifier : (n,) float
Vector of properties
sigfig : (n,) int
Number of sigfigs per property
Returns
----------
md5 : str
... | python | {
"resource": ""
} |
q23274 | convert_to_vertexlist | train | def convert_to_vertexlist(geometry, **kwargs):
"""
Try to convert various geometry objects to the constructor
args for a pyglet indexed vertex list.
Parameters
------------
obj : Trimesh, Path2D, Path3D, (n,2) float, (n,3) float
Object to render
Returns
------------
args : tu... | python | {
"resource": ""
} |
q23275 | mesh_to_vertexlist | train | def mesh_to_vertexlist(mesh,
group=None,
smooth=True,
smooth_threshold=60000):
"""
Convert a Trimesh object to arguments for an
indexed vertex list constructor.
Parameters
-------------
mesh : trimesh.Trimesh
Mesh to be ... | python | {
"resource": ""
} |
q23276 | path_to_vertexlist | train | def path_to_vertexlist(path, group=None, colors=None, **kwargs):
"""
Convert a Path3D object to arguments for an
indexed vertex list constructor.
Parameters
-------------
path : trimesh.path.Path3D object
Mesh to be rendered
group : str
Rendering group for the vertex list
R... | python | {
"resource": ""
} |
q23277 | points_to_vertexlist | train | def points_to_vertexlist(points,
colors=None,
group=None,
**kwargs):
"""
Convert a numpy array of 3D points to args for
a vertex list constructor.
Parameters
-------------
points : (n, 3) float
Points to be rendere... | python | {
"resource": ""
} |
q23278 | material_to_texture | train | def material_to_texture(material):
"""
Convert a trimesh.visual.texture.Material object into
a pyglet- compatible texture object.
Parameters
--------------
material : trimesh.visual.texture.Material
Material to be converted
Returns
---------------
texture : pyglet.image.Textu... | python | {
"resource": ""
} |
q23279 | matrix_to_gl | train | def matrix_to_gl(matrix):
"""
Convert a numpy row- major homogenous transformation matrix
to a flat column- major GLfloat transformation.
Parameters
-------------
matrix : (4,4) float
Row- major homogenous transform
Returns
-------------
glmatrix : (16,) gl.GLfloat
Tran... | python | {
"resource": ""
} |
q23280 | vector_to_gl | train | def vector_to_gl(array, *args):
"""
Convert an array and an optional set of args into a
flat vector of gl.GLfloat
"""
array = np.array(array)
if len(args) > 0:
array = np.append(array, args)
vector = (gl.GLfloat * len(array))(*array)
return vector | python | {
"resource": ""
} |
q23281 | light_to_gl | train | def light_to_gl(light, transform, lightN):
"""
Convert trimesh.scene.lighting.Light objects into
args for gl.glLightFv calls
Parameters
--------------
light : trimesh.scene.lighting.Light
Light object to be converted to GL
transform : (4, 4) float
Transformation matrix of light
... | python | {
"resource": ""
} |
q23282 | Trackball.down | train | def down(self, point):
"""Record an initial mouse press at a given point.
Parameters
----------
point : (2,) int
The x and y pixel coordinates of the mouse press.
"""
self._pdown = np.array(point, dtype=np.float32)
self._pose = self._n_pose
se... | python | {
"resource": ""
} |
q23283 | Trackball.drag | train | def drag(self, point):
"""Update the tracball during a drag.
Parameters
----------
point : (2,) int
The current x and y pixel coordinates of the mouse during a drag.
This will compute a movement for the trackball with the relative
motion between this ... | python | {
"resource": ""
} |
q23284 | Trackball.scroll | train | def scroll(self, clicks):
"""Zoom using a mouse scroll wheel motion.
Parameters
----------
clicks : int
The number of clicks. Positive numbers indicate forward wheel
movement.
"""
target = self._target
ratio = 0.90
mult = 1.0
... | python | {
"resource": ""
} |
q23285 | Trackball.rotate | train | def rotate(self, azimuth, axis=None):
"""Rotate the trackball about the "Up" axis by azimuth radians.
Parameters
----------
azimuth : float
The number of radians to rotate.
"""
target = self._target
y_axis = self._n_pose[:3, 1].flatten()
if a... | python | {
"resource": ""
} |
q23286 | look_at | train | def look_at(points, fov, rotation=None, distance=None, center=None):
"""
Generate transform for a camera to keep a list
of points in the camera's field of view.
Parameters
-------------
points : (n, 3) float
Points in space
fov : (2,) float
Field of view, in DEGREES
rotation... | python | {
"resource": ""
} |
q23287 | camera_to_rays | train | def camera_to_rays(camera):
"""
Convert a trimesh.scene.Camera object to ray origins
and direction vectors. Will return one ray per pixel,
as set in camera.resolution.
Parameters
--------------
camera : trimesh.scene.Camera
Camera with transform defined
Returns
--------------... | python | {
"resource": ""
} |
q23288 | Camera.resolution | train | def resolution(self, values):
"""
Set the camera resolution in pixels.
Parameters
------------
resolution (2,) float
Camera resolution in pixels
"""
values = np.asanyarray(values, dtype=np.int64)
if values.shape != (2,):
raise ValueE... | python | {
"resource": ""
} |
q23289 | Camera.scene | train | def scene(self, value):
"""
Set the reference to the scene that this camera is in.
Parameters
-------------
scene : None, or trimesh.Scene
Scene where this camera is attached
"""
# save the scene reference
self._scene = value
# check i... | python | {
"resource": ""
} |
q23290 | Camera.focal | train | def focal(self):
"""
Get the focal length in pixels for the camera.
Returns
------------
focal : (2,) float
Focal length in pixels
"""
if self._focal is None:
# calculate focal length from FOV
focal = [(px / 2.0) / np.tan(np.radi... | python | {
"resource": ""
} |
q23291 | Camera.K | train | def K(self):
"""
Get the intrinsic matrix for the Camera object.
Returns
-----------
K : (3, 3) float
Intrinsic matrix for camera
"""
K = np.eye(3, dtype=np.float64)
K[0, 0] = self.focal[0]
K[1, 1] = self.focal[1]
K[0, 2] = self.... | python | {
"resource": ""
} |
q23292 | Camera.fov | train | def fov(self):
"""
Get the field of view in degrees.
Returns
-------------
fov : (2,) float
XY field of view in degrees
"""
if self._fov is None:
fov = [2.0 * np.degrees(np.arctan((px / 2.0) / f))
for px, f in zip(self._re... | python | {
"resource": ""
} |
q23293 | Camera.fov | train | def fov(self, values):
"""
Set the field of view in degrees.
Parameters
-------------
values : (2,) float
Size of FOV to set in degrees
"""
if values is None:
self._fov = None
else:
values = np.asanyarray(values, dtype=np... | python | {
"resource": ""
} |
q23294 | sinwave | train | def sinwave(scene):
"""
A callback passed to a scene viewer which will update
transforms in the viewer periodically.
Parameters
-------------
scene : trimesh.Scene
Scene containing geometry
"""
# create an empty homogenous transformation
matrix = np.eye(4)
# set Y as cos ... | python | {
"resource": ""
} |
q23295 | to_volume | train | def to_volume(mesh,
file_name=None,
max_element=None,
mesher_id=1):
"""
Convert a surface mesh to a 3D volume mesh generated by gmsh.
An easy way to install the gmsh sdk is through the gmsh-sdk
package on pypi, which downloads and sets up gmsh:
pip inst... | python | {
"resource": ""
} |
q23296 | local_voxelize | train | def local_voxelize(mesh, point, pitch, radius, fill=True, **kwargs):
"""
Voxelize a mesh in the region of a cube around a point. When fill=True,
uses proximity.contains to fill the resulting voxels so may be meaningless
for non-watertight meshes. Useful to reduce memory cost for small values of
pitc... | python | {
"resource": ""
} |
q23297 | voxelize_ray | train | def voxelize_ray(mesh,
pitch,
per_cell=[2, 2],
**kwargs):
"""
Voxelize a mesh using ray queries.
Parameters
-------------
mesh : Trimesh object
Mesh to be voxelized
pitch : float
Length of voxel cube
... | python | {
"resource": ""
} |
q23298 | fill_voxelization | train | def fill_voxelization(occupied):
"""
Given a sparse surface voxelization, fill in between columns.
Parameters
--------------
occupied: (n, 3) int, location of filled cells
Returns
--------------
filled: (m, 3) int, location of filled cells
"""
# validate inputs
occupied = n... | python | {
"resource": ""
} |
q23299 | multibox | train | def multibox(centers, pitch, colors=None):
"""
Return a Trimesh object with a box at every center.
Doesn't do anything nice or fancy.
Parameters
-----------
centers: (n,3) float, center of boxes that are occupied
pitch: float, the edge length of a voxel
colors: (3,) or (4,) or (n,3) ... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.