Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
10,656 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
try: | ||
import generic as g | ||
except BaseException: | ||
from . import generic as g | ||
|
||
|
||
class STEPTests(g.unittest.TestCase): | ||
def test_basic(self): | ||
try: | ||
import cascadio # noqa | ||
except BaseException: | ||
g.log.error("failed to get cascadio!", exc_info=True) | ||
return | ||
|
||
s = g.get_mesh("box_sides.STEP") | ||
assert len(s.geometry) == 10 | ||
|
||
|
||
if __name__ == "__main__": | ||
g.trimesh.util.attach_to_log() | ||
g.unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import os | ||
import tempfile | ||
|
||
from ..typed import BinaryIO, Dict, Optional | ||
|
||
# used as an intermediate format | ||
from .gltf import load_glb | ||
|
||
|
||
def load_step( | ||
file_obj: BinaryIO, | ||
file_type, | ||
tol_linear: Optional[float] = None, | ||
tol_angular: Optional[float] = None, | ||
tol_relative: Optional[bool] = False, | ||
merge_primitives: bool = True, | ||
**kwargs, | ||
) -> Dict: | ||
""" | ||
Use `cascadio` a packaged version of OpenCASCADE | ||
to load a STEP file using GLB as an intermediate. | ||
Parameters | ||
----------- | ||
file_obj | ||
STEP file to load. | ||
**kwargs | ||
Passed to `cascadio.step_to_glb` | ||
Returns | ||
---------- | ||
kwargs | ||
Keyword arguments for a Scene. | ||
""" | ||
# TODO : update upstream `cascadio` to accept bytes objects | ||
# so that we don't need to write a temporary file to disc! | ||
with tempfile.TemporaryDirectory() as F: | ||
# temporarily copy the STEP | ||
stepfile = os.path.join(F, "data.step") | ||
with open(stepfile, "wb") as f: | ||
f.write(file_obj.read()) | ||
|
||
# where to save the converted GLB | ||
glbfile = os.path.join(F, "converted.glb") | ||
|
||
# the arguments for cascadio are not optional so | ||
# filter out any `None` value arguments here | ||
cascadio_kwargs = { | ||
"merge_primitives": bool(merge_primitives), | ||
"tol_linear": tol_linear, | ||
"tol_angular": tol_angular, | ||
"tol_relative": tol_relative, | ||
} | ||
# run the conversion | ||
cascadio.step_to_glb( | ||
stepfile, | ||
glbfile, | ||
**{k: v for k, v in cascadio_kwargs.items() if v is not None}, | ||
) | ||
|
||
with open(glbfile, "rb") as f: | ||
# return the parsed intermediate file | ||
return load_glb(file_obj=f, merge_primitives=merge_primitives, **kwargs) | ||
|
||
|
||
try: | ||
# wheels for most platforms: `pip install cascadio` | ||
import cascadio | ||
|
||
_cascade_loaders = {"stp": load_step, "step": load_step} | ||
except BaseException: | ||
_cascade_loaders = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters