Skip to content

Commit

Permalink
Merge pull request #2075 from mikedh/feat/ukey
Browse files Browse the repository at this point in the history
Release: load_remote to httpx
  • Loading branch information
mikedh authored Nov 23, 2023
2 parents 46b6aaf + bd06c65 commit 82466bd
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = ["setuptools >= 61.0", "wheel"]
[project]
name = "trimesh"
requires-python = ">=3.7"
version = "4.0.4"
version = "4.0.5"
authors = [{name = "Michael Dawson-Haggerty", email = "mikedh@kerfed.com"}]
license = {file = "LICENSE.md"}
description = "Import, export, process, analyze and view triangular meshes."
Expand Down Expand Up @@ -73,7 +73,7 @@ easy = [
"shapely",
"xxhash",
"rtree",
"requests",
"httpx",
"scipy",
"embreex",
"pillow",
Expand Down
9 changes: 4 additions & 5 deletions tests/test_dae.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_duck(self):
assert len(scene.graph.nodes_geometry) == 1

conv = scene.convert_units("inch")
assert conv.units == 'inch'
assert conv.units == "inch"

def test_shoulder(self):
if collada is None:
Expand All @@ -40,9 +40,9 @@ def test_shoulder(self):
assert len(scene.geometry) == 3
assert len(scene.graph.nodes_geometry) == 3

assert scene.units != 'mm'
assert scene.units != "mm"
conv = scene.convert_units("mm")
assert conv.units == 'mm'
assert conv.units == "mm"

def test_export(self):
if collada is None:
Expand All @@ -67,8 +67,7 @@ def test_obj_roundtrip(self):
assert s.visual.material.baseColorTexture.size == rec.visual.material.image.size

conv = s.convert_units("inch")
assert conv.units == 'inch'

assert conv.units == "inch"

def test_material_round(self):
"""
Expand Down
5 changes: 5 additions & 0 deletions tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def test_path(self):
# extents should scale exactly with unit conversion
assert g.np.allclose(p.extents / extents_pre, 25.4, atol=0.01)

def test_keys(self):
units = g.trimesh.units.keys()
assert isinstance(units, set)
assert "in" in units

def test_arbitrary(self):
ac = g.np.allclose
to_inch = g.trimesh.units.to_inch
Expand Down
6 changes: 4 additions & 2 deletions trimesh/exchange/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,12 @@ def load_remote(url, **kwargs):
Loaded result
"""
# import here to keep requirement soft
import requests
import httpx

# download the mesh
response = requests.get(url)
response = httpx.get(url, follow_redirects=True)
response.raise_for_status()

# wrap as file object
file_obj = util.wrap_as_stream(response.content)

Expand Down
12 changes: 6 additions & 6 deletions trimesh/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def get(self, name):
Asset name, i.e. 'quadknot.obj.mtl'
"""
# do import here to keep soft dependency
import requests
import httpx

# remove leading and trailing whitespace
name = name.strip()
Expand All @@ -363,16 +363,16 @@ def get(self, name):
# base url has been carefully formatted
url = self.base_url + name

response = requests.get(url)
response = httpx.get(url, follow_redirects=True)

if response.status_code != 200:
if response.status_code >= 300:
# try to strip off filesystem crap
if name.startswith("./"):
name = name[2:]
response = requests.get(self.base_url + name)
response = httpx.get(self.base_url + name, follow_redirects=True)

if response.status_code == "404":
raise ValueError(response.content)
# now raise if we don't have
response.raise_for_status()

# return the bytes of the response
return response.content
Expand Down
12 changes: 12 additions & 0 deletions trimesh/units.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def unit_conversion(current: str, desired: str) -> float:
return to_inch(current.strip().lower()) / to_inch(desired.strip().lower())


def keys() -> set:
"""
Return a set containing all currently valid units.
Returns
--------
keys
All units with conversions i.e. {'in', 'm', ...}
"""
return set(_lookup.keys())


def to_inch(unit: str) -> float:
"""
Calculate the conversion to an arbitrary common unit.
Expand Down
4 changes: 1 addition & 3 deletions trimesh/visual/gloss.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ def get_specular_glossiness(
or specularGlossinessTexture.shape[-1]
) == 1:
# use the one channel as a multiplier for specular and glossiness
specularTexture = glossinessTexture = specularGlossinessTexture.reshape(
(-1, -1, 1)
)
specularTexture = glossinessTexture = specularGlossinessTexture[..., np.newaxis]
elif specularGlossinessTexture.shape[-1] == 3:
# all channels are specular, glossiness is only a factor
specularTexture = specularGlossinessTexture[..., :3]
Expand Down

0 comments on commit 82466bd

Please sign in to comment.