Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release: Refactor Load Types #2241

Open
wants to merge 63 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
ed9de89
basic outline of return types
mikedh Jun 13, 2024
5df249f
resolver type hints
mikedh Jun 17, 2024
78567b7
3~BABMerge branch 'main' into refactor/loadtype
mikedh Jul 11, 2024
3553255
merge main and try lighter touch
mikedh Jul 11, 2024
9aa327d
merge main
mikedh Jul 11, 2024
30ca68b
merge
mikedh Sep 1, 2024
e5732dc
merge main
mikedh Oct 22, 2024
84b5565
wip
mikedh Oct 23, 2024
c73170c
Updated use of weights in procrustes analysis.
Oct 30, 2024
20dc9ed
Fix nearest.ipynb Typo
Tallerpie Dec 1, 2024
145ba83
Merge pull request #2313 from tillns/main
mikedh Dec 3, 2024
1ac2419
Merge pull request #2327 from Tallerpie/patch-1
mikedh Dec 3, 2024
6dedb95
update test_scenegraph to pytest style
mikedh Dec 3, 2024
209d0a5
codespell
mikedh Dec 3, 2024
52737d8
change test
mikedh Dec 3, 2024
4833682
Merge branch 'main' into refactor/loadtype
mikedh Dec 3, 2024
942ac83
pass test_minimal anyway
mikedh Dec 3, 2024
6d4e34e
pass test_loaded
mikedh Dec 3, 2024
a1e6877
move all fetching into WebResolver
mikedh Dec 3, 2024
6e7fd43
fix some metadata passing
mikedh Dec 3, 2024
9a8e969
hmm
mikedh Dec 3, 2024
f2f079a
metadata to every geometry
mikedh Dec 4, 2024
5d71ab1
try matching old behavior
mikedh Dec 4, 2024
9645641
fix more tests
mikedh Dec 4, 2024
75fd8cc
fix test_gltf
mikedh Dec 4, 2024
e76ce2b
off also return mesh
mikedh Dec 4, 2024
751ec61
match more old behavior
mikedh Dec 4, 2024
181dbcb
fix test_scene
mikedh Dec 5, 2024
a25082b
fix for #2330
mikedh Dec 15, 2024
f5b9b55
need a metadata policy
mikedh Dec 16, 2024
d608c3a
apply Jan25 resources.get deprecation
mikedh Dec 16, 2024
ff2a542
fix and test voxels in scenes
mikedh Dec 17, 2024
8d4693c
fix and test #2335
mikedh Dec 26, 2024
5b580b6
fix rounding issue in uv_to_color()
TooSchoolForCool Dec 27, 2024
c46eca1
Merge pull request #2336 from TooSchoolForCool/main
mikedh Jan 2, 2025
693081a
Merge pull request #2328 from mikedh/release/weight
mikedh Jan 2, 2025
a5ca023
fix and test divide-by-zero in visual.interpolate
mikedh Jan 2, 2025
08328c3
try tacking on load info as an attribute
mikedh Jan 2, 2025
6b5373e
deprecate Path3D.to_planar->Path3D.to_2D
mikedh Jan 9, 2025
f8dbf9a
fix test_gltf
mikedh Jan 9, 2025
273c92d
fix deprecation wrapper
mikedh Jan 9, 2025
381abe7
blender booleans
mikedh Jan 10, 2025
37b93e9
wrap _uri_to_bytes
mikedh Jan 12, 2025
94d35f5
fixed not loading point cloud colors from glb format files
henryzhengr Jan 14, 2025
f50e262
include a LoadSource for all geometry
mikedh Jan 14, 2025
eb4a088
run blender tests
mikedh Jan 14, 2025
13d1d65
make source available more easily
mikedh Jan 14, 2025
517fecb
should source really be optional
mikedh Jan 14, 2025
aa7e826
py38 syntax
mikedh Jan 14, 2025
90409b4
clean up and expand corpus and fix surfaced bugs
mikedh Jan 14, 2025
83425db
fix more tests
mikedh Jan 15, 2025
eb60b49
try adding in weights
mikedh Jan 15, 2025
63a92f6
some type fixes
mikedh Jan 15, 2025
24d2db1
add missing import
mikedh Jan 16, 2025
c3c858d
fix deepcopy override
mikedh Jan 16, 2025
fab9580
load_dict shenanigans
mikedh Jan 16, 2025
837270e
fix util type hint
mikedh Jan 16, 2025
780a572
run corpus again
mikedh Jan 16, 2025
eaa6004
remove dae until pycollada/pycollada/147 releases
mikedh Jan 16, 2025
ffdc7eb
add report logic
mikedh Jan 17, 2025
f72cef9
apply march 2024 deprecation of graph.smoothed
mikedh Jan 17, 2025
d0e0ac9
disable dae
mikedh Jan 17, 2025
a94c287
fixed not loading point cloud colors from glb format files (#2339)
mikedh Jan 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
apply Jan25 resources.get deprecation
  • Loading branch information
mikedh committed Dec 16, 2024
commit d608c3ad523c938d0191692421780591f12c0dca
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -120,6 +120,7 @@ test_more = [
"matplotlib",
"pymeshlab",
"triangle",
"ipython",
]

# interfaces.gmsh will be dropped Jan 2025
4 changes: 2 additions & 2 deletions trimesh/exchange/load.py
Original file line number Diff line number Diff line change
@@ -514,7 +514,7 @@ def handle_pointcloud():
@dataclass
class _FileArgs:
# a file-like object that can be accessed
file_obj: Stream
file_obj: Optional[Stream]

# a cleaned file type string, i.e. "stl"
file_type: str
@@ -526,7 +526,7 @@ class _FileArgs:
was_opened: bool

# a resolver for loading assets next to the file
resolver: resolvers.ResolverLike
resolver: Optional[resolvers.ResolverLike]


def _parse_file_args(
104 changes: 23 additions & 81 deletions trimesh/resources/__init__.py
Original file line number Diff line number Diff line change
@@ -1,84 +1,15 @@
import json
import os
import warnings
from io import BytesIO

from ..typed import Dict, Stream
from ..util import decode_text, wrap_as_stream
from ..typed import Dict

# find the current absolute path to this directory
_pwd = os.path.expanduser(os.path.abspath(os.path.dirname(__file__)))

# once resources are loaded cache them
_cache = {}


def get(
name: str, decode: bool = True, decode_json: bool = False, as_stream: bool = False
):
"""
DERECATED JANUARY 2025 REPLACE WITH TYPED `get_json`, `get_string`, etc.
"""
warnings.warn(
"`trimesh.resources.get` is deprecated "
+ "and will be removed in January 2025: "
+ "replace with typed `trimesh.resources.get_*type*`",
category=DeprecationWarning,
stacklevel=2,
)
return _get(name=name, decode=decode, decode_json=decode_json, as_stream=as_stream)


def _get(name: str, decode: bool, decode_json: bool, as_stream: bool):
"""
Get a resource from the `trimesh/resources` folder.

Parameters
-------------
name : str
File path relative to `trimesh/resources`
decode : bool
Whether or not to decode result as UTF-8
decode_json : bool
Run `json.loads` on resource if True.
as_stream : bool
Return as a file-like object

Returns
-------------
resource : str, bytes, or decoded JSON
File data
"""

# key by name and decode
cache_key = (name, bool(decode), bool(decode_json), bool(as_stream))
cached = _cache.get(cache_key)
if hasattr(cached, "seek"):
cached.seek(0)
if cached is not None:
return cached

# get the resource using relative names
# all templates are using POSIX relative paths
# so fix them to be platform-specific
with open(os.path.join(_pwd, *name.split("/")), "rb") as f:
resource = f.read()

# make sure we return it as a string if asked
if decode:
# will decode into text if possibly
resource = decode_text(resource)

if decode_json:
resource = json.loads(resource)
elif as_stream:
resource = wrap_as_stream(resource)

# store for later access
_cache[cache_key] = resource

return resource


def get_schema(name: str) -> Dict:
"""
Load a schema and evaluate the referenced files.
@@ -98,8 +29,8 @@ def get_schema(name: str) -> Dict:

# get a resolver for our base path
resolver = FilePathResolver(os.path.join(_pwd, "schema", name))
# recursively load $ref keys
return resolve(json.loads(decode_text(resolver.get(name))), resolver=resolver)
# recursively load `$ref` keys
return resolve(json.loads(resolver.get(name).decode("utf-8")), resolver=resolver)


def get_json(name: str) -> Dict:
@@ -109,14 +40,14 @@ def get_json(name: str) -> Dict:
Parameters
-------------
name : str
File path relative to `trimesh/resources`
File path relative to `trimesh/resources/{name}`

Returns
-------------
resource
File data decoded from JSON.
"""
return _get(name, decode=True, decode_json=True, as_stream=False)
return json.loads(get_bytes(name).decode("utf-8"))


def get_string(name: str) -> str:
@@ -125,15 +56,15 @@ def get_string(name: str) -> str:

Parameters
-------------
name : str
name
File path relative to `trimesh/resources`

Returns
-------------
resource
File data as a string.
"""
return _get(name, decode=True, decode_json=False, as_stream=False)
return get_bytes(name).decode("utf-8")


def get_bytes(name: str) -> bytes:
@@ -142,18 +73,29 @@ def get_bytes(name: str) -> bytes:

Parameters
-------------
name : str
name
File path relative to `trimesh/resources`

Returns
-------------
resource
File data as raw bytes.
"""
return _get(name, decode=False, decode_json=False, as_stream=False)
cached = _cache.get(name, None)
if cached is not None:
return cached

# get the resource using relative names
# all templates are using POSIX relative paths
# so fix them to be platform-specific
with open(os.path.join(_pwd, *name.split("/")), "rb") as f:
resource = f.read()

_cache[name] = resource
return resource


def get_stream(name: str) -> Stream:
def get_stream(name: str) -> BytesIO:
"""
Get a resource from the `trimesh/resources` folder as a binary stream.

@@ -168,4 +110,4 @@ def get_stream(name: str) -> Stream:
File data as a binary stream.
"""

return _get(name, decode=False, decode_json=False, as_stream=True)
return BytesIO(get_bytes(name))
Loading