COMPAS 2.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compas/__init__.py +274 -0
- compas/__main__.py +31 -0
- compas/_iotools.py +80 -0
- compas/_os.py +746 -0
- compas/colors/__init__.py +14 -0
- compas/colors/cmcrameri/acton.txt +256 -0
- compas/colors/cmcrameri/actonS.txt +100 -0
- compas/colors/cmcrameri/bam.txt +256 -0
- compas/colors/cmcrameri/bamO.txt +256 -0
- compas/colors/cmcrameri/bamako.txt +256 -0
- compas/colors/cmcrameri/bamakoS.txt +100 -0
- compas/colors/cmcrameri/batlow.txt +256 -0
- compas/colors/cmcrameri/batlowK.txt +256 -0
- compas/colors/cmcrameri/batlowS.txt +100 -0
- compas/colors/cmcrameri/batlowW.txt +256 -0
- compas/colors/cmcrameri/berlin.txt +256 -0
- compas/colors/cmcrameri/bilbao.txt +256 -0
- compas/colors/cmcrameri/bilbaoS.txt +100 -0
- compas/colors/cmcrameri/broc.txt +256 -0
- compas/colors/cmcrameri/brocO.txt +256 -0
- compas/colors/cmcrameri/buda.txt +256 -0
- compas/colors/cmcrameri/budaS.txt +100 -0
- compas/colors/cmcrameri/bukavu.txt +256 -0
- compas/colors/cmcrameri/cork.txt +256 -0
- compas/colors/cmcrameri/corkO.txt +256 -0
- compas/colors/cmcrameri/davos.txt +256 -0
- compas/colors/cmcrameri/davosS.txt +100 -0
- compas/colors/cmcrameri/devon.txt +256 -0
- compas/colors/cmcrameri/devonS.txt +100 -0
- compas/colors/cmcrameri/fes.txt +256 -0
- compas/colors/cmcrameri/grayC.txt +256 -0
- compas/colors/cmcrameri/grayCS.txt +100 -0
- compas/colors/cmcrameri/hawaii.txt +256 -0
- compas/colors/cmcrameri/hawaiiS.txt +100 -0
- compas/colors/cmcrameri/imola.txt +256 -0
- compas/colors/cmcrameri/imolaS.txt +100 -0
- compas/colors/cmcrameri/lajolla.txt +256 -0
- compas/colors/cmcrameri/lajollaS.txt +100 -0
- compas/colors/cmcrameri/lapaz.txt +256 -0
- compas/colors/cmcrameri/lapazS.txt +100 -0
- compas/colors/cmcrameri/lisbon.txt +256 -0
- compas/colors/cmcrameri/nuuk.txt +256 -0
- compas/colors/cmcrameri/nuukS.txt +100 -0
- compas/colors/cmcrameri/oleron.txt +256 -0
- compas/colors/cmcrameri/oslo.txt +256 -0
- compas/colors/cmcrameri/osloS.txt +100 -0
- compas/colors/cmcrameri/roma.txt +256 -0
- compas/colors/cmcrameri/romaO.txt +256 -0
- compas/colors/cmcrameri/tofino.txt +256 -0
- compas/colors/cmcrameri/tokyo.txt +256 -0
- compas/colors/cmcrameri/tokyoS.txt +100 -0
- compas/colors/cmcrameri/turku.txt +256 -0
- compas/colors/cmcrameri/turkuS.txt +100 -0
- compas/colors/cmcrameri/vanimo.txt +256 -0
- compas/colors/cmcrameri/vik.txt +256 -0
- compas/colors/cmcrameri/vikO.txt +256 -0
- compas/colors/color.py +1118 -0
- compas/colors/colordict.py +103 -0
- compas/colors/colormap.py +306 -0
- compas/colors/html_colors.py +149 -0
- compas/colors/mpl_colormap.py +1064 -0
- compas/data/__init__.py +31 -0
- compas/data/coercion.py +71 -0
- compas/data/conftest.py +10 -0
- compas/data/data.py +342 -0
- compas/data/encoders.py +240 -0
- compas/data/exceptions.py +2 -0
- compas/data/json.py +240 -0
- compas/data/samples/boxes.obj +250 -0
- compas/data/samples/butt_model.obj +2829 -0
- compas/data/samples/cone.stl +0 -0
- compas/data/samples/cube.off +16 -0
- compas/data/samples/cube_ascii.stl +56114 -0
- compas/data/samples/cube_binary.stl +0 -0
- compas/data/samples/cube_binary_2.stl +0 -0
- compas/data/samples/doosabin.json +1 -0
- compas/data/samples/faces.obj +63 -0
- compas/data/samples/faces_big.obj +9663 -0
- compas/data/samples/faces_reversed.obj +63 -0
- compas/data/samples/fink.obj +135 -0
- compas/data/samples/grid_irregular.obj +303 -0
- compas/data/samples/hypar.obj +148 -0
- compas/data/samples/lines.json +1 -0
- compas/data/samples/lines.obj +282 -0
- compas/data/samples/lines_big.obj +40322 -0
- compas/data/samples/lines_bigger.obj +161282 -0
- compas/data/samples/lines_noleaves.obj +422 -0
- compas/data/samples/mesh.obj +874 -0
- compas/data/samples/mesh_100_faces.json +1893 -0
- compas/data/samples/mesh_110_faces.json +2081 -0
- compas/data/samples/open_edges.obj +424 -0
- compas/data/samples/point.json +1 -0
- compas/data/samples/quadmesh.obj +183 -0
- compas/data/samples/quadmesh_planar.obj +181 -0
- compas/data/samples/saddle.obj +314 -0
- compas/data/samples/spline.obj +72 -0
- compas/data/samples/tubemesh.json +1 -0
- compas/data/samples/tubemesh.obj +378 -0
- compas/data/samples/tubemesh.off +374 -0
- compas/data/samples/tubemesh.ply +551 -0
- compas/data/schema.py +137 -0
- compas/data/validators.py +243 -0
- compas/datastructures/__init__.py +75 -0
- compas/datastructures/_mutablemapping.py +148 -0
- compas/datastructures/assembly/__init__.py +0 -0
- compas/datastructures/assembly/assembly.py +234 -0
- compas/datastructures/assembly/exceptions.py +6 -0
- compas/datastructures/assembly/part.py +228 -0
- compas/datastructures/attributes.py +85 -0
- compas/datastructures/cell_network/__init__.py +0 -0
- compas/datastructures/cell_network/cell_network.py +4190 -0
- compas/datastructures/datastructure.py +309 -0
- compas/datastructures/graph/__init__.py +0 -0
- compas/datastructures/graph/duality.py +197 -0
- compas/datastructures/graph/graph.py +2478 -0
- compas/datastructures/graph/operations/__init__.py +0 -0
- compas/datastructures/graph/operations/join.py +124 -0
- compas/datastructures/graph/operations/split.py +63 -0
- compas/datastructures/graph/planarity.py +292 -0
- compas/datastructures/graph/smoothing.py +59 -0
- compas/datastructures/mesh/__init__.py +0 -0
- compas/datastructures/mesh/conway.py +553 -0
- compas/datastructures/mesh/duality.py +104 -0
- compas/datastructures/mesh/mesh.py +5103 -0
- compas/datastructures/mesh/operations/__init__.py +0 -0
- compas/datastructures/mesh/operations/collapse.py +350 -0
- compas/datastructures/mesh/operations/extrude.py +0 -0
- compas/datastructures/mesh/operations/insert.py +120 -0
- compas/datastructures/mesh/operations/merge.py +83 -0
- compas/datastructures/mesh/operations/split.py +263 -0
- compas/datastructures/mesh/operations/substitute.py +37 -0
- compas/datastructures/mesh/operations/swap.py +62 -0
- compas/datastructures/mesh/operations/weld.py +107 -0
- compas/datastructures/mesh/remesh.py +234 -0
- compas/datastructures/mesh/slice.py +170 -0
- compas/datastructures/mesh/smoothing.py +187 -0
- compas/datastructures/mesh/subdivision.py +754 -0
- compas/datastructures/tree/__init__.py +0 -0
- compas/datastructures/tree/tree.py +504 -0
- compas/datastructures/volmesh/__init__.py +0 -0
- compas/datastructures/volmesh/volmesh.py +4203 -0
- compas/files/__init__.py +27 -0
- compas/files/_xml/__init__.py +0 -0
- compas/files/_xml/xml_cli.py +213 -0
- compas/files/_xml/xml_cpython.py +32 -0
- compas/files/_xml/xml_pre_38.py +58 -0
- compas/files/_xml/xml_shared.py +40 -0
- compas/files/gltf/__init__.py +0 -0
- compas/files/gltf/constants.py +59 -0
- compas/files/gltf/data_classes.py +657 -0
- compas/files/gltf/extensions.py +317 -0
- compas/files/gltf/gltf.py +92 -0
- compas/files/gltf/gltf_children.py +64 -0
- compas/files/gltf/gltf_content.py +615 -0
- compas/files/gltf/gltf_exporter.py +465 -0
- compas/files/gltf/gltf_mesh.py +273 -0
- compas/files/gltf/gltf_node.py +348 -0
- compas/files/gltf/gltf_parser.py +115 -0
- compas/files/gltf/gltf_reader.py +310 -0
- compas/files/gltf/gltf_scene.py +125 -0
- compas/files/gltf/helpers.py +59 -0
- compas/files/obj.py +680 -0
- compas/files/off.py +296 -0
- compas/files/ply.py +697 -0
- compas/files/stl.py +436 -0
- compas/files/xml.py +328 -0
- compas/geometry/__init__.py +772 -0
- compas/geometry/_core/__init__.py +0 -0
- compas/geometry/_core/_algebra.py +2826 -0
- compas/geometry/_core/angles.py +408 -0
- compas/geometry/_core/centroids.py +573 -0
- compas/geometry/_core/distance.py +895 -0
- compas/geometry/_core/normals.py +149 -0
- compas/geometry/_core/nurbs.py +367 -0
- compas/geometry/_core/predicates_2.py +582 -0
- compas/geometry/_core/predicates_3.py +1111 -0
- compas/geometry/_core/quaternions.py +196 -0
- compas/geometry/_core/size.py +204 -0
- compas/geometry/_core/tangent.py +56 -0
- compas/geometry/_core/transformations.py +1121 -0
- compas/geometry/_core/transformations_numpy.py +279 -0
- compas/geometry/bbox.py +145 -0
- compas/geometry/bbox_numpy.py +306 -0
- compas/geometry/bestfit.py +77 -0
- compas/geometry/bestfit_numpy.py +259 -0
- compas/geometry/booleans.py +297 -0
- compas/geometry/booleans_shapely.py +147 -0
- compas/geometry/brep/__init__.py +112 -0
- compas/geometry/brep/brep.py +1131 -0
- compas/geometry/brep/edge.py +302 -0
- compas/geometry/brep/errors.py +22 -0
- compas/geometry/brep/face.py +329 -0
- compas/geometry/brep/loop.py +87 -0
- compas/geometry/brep/trim.py +46 -0
- compas/geometry/brep/vertex.py +46 -0
- compas/geometry/contours.py +32 -0
- compas/geometry/curves/__init__.py +0 -0
- compas/geometry/curves/arc.py +429 -0
- compas/geometry/curves/bezier.py +345 -0
- compas/geometry/curves/circle.py +500 -0
- compas/geometry/curves/conic.py +16 -0
- compas/geometry/curves/curve.py +614 -0
- compas/geometry/curves/ellipse.py +408 -0
- compas/geometry/curves/hyperbola.py +336 -0
- compas/geometry/curves/line.py +431 -0
- compas/geometry/curves/nurbs.py +412 -0
- compas/geometry/curves/parabola.py +256 -0
- compas/geometry/curves/polyline.py +724 -0
- compas/geometry/frame.py +769 -0
- compas/geometry/geometry.py +296 -0
- compas/geometry/hull.py +146 -0
- compas/geometry/hull_numpy.py +82 -0
- compas/geometry/icp_numpy.py +104 -0
- compas/geometry/interpolation_barycentric.py +38 -0
- compas/geometry/interpolation_coons.py +102 -0
- compas/geometry/interpolation_tweening.py +87 -0
- compas/geometry/intersection.py +121 -0
- compas/geometry/intersections.py +1105 -0
- compas/geometry/kdtree.py +153 -0
- compas/geometry/offset.py +208 -0
- compas/geometry/pca_numpy.py +87 -0
- compas/geometry/plane.py +657 -0
- compas/geometry/point.py +664 -0
- compas/geometry/pointcloud.py +409 -0
- compas/geometry/polygon.py +473 -0
- compas/geometry/polyhedron.py +650 -0
- compas/geometry/projection.py +155 -0
- compas/geometry/quadmesh_planarize.py +30 -0
- compas/geometry/quadmesh_planarize_none.py +114 -0
- compas/geometry/quaternion.py +544 -0
- compas/geometry/reflection.py +102 -0
- compas/geometry/rotation.py +354 -0
- compas/geometry/scale.py +100 -0
- compas/geometry/shapes/__init__.py +0 -0
- compas/geometry/shapes/box.py +747 -0
- compas/geometry/shapes/capsule.py +472 -0
- compas/geometry/shapes/cone.py +309 -0
- compas/geometry/shapes/cylinder.py +355 -0
- compas/geometry/shapes/shape.py +300 -0
- compas/geometry/shapes/sphere.py +362 -0
- compas/geometry/shapes/torus.py +294 -0
- compas/geometry/shear.py +115 -0
- compas/geometry/surfaces/__init__.py +0 -0
- compas/geometry/surfaces/conical.py +166 -0
- compas/geometry/surfaces/cylindrical.py +251 -0
- compas/geometry/surfaces/extrusion.py +0 -0
- compas/geometry/surfaces/nurbs.py +380 -0
- compas/geometry/surfaces/planar.py +223 -0
- compas/geometry/surfaces/revolution.py +0 -0
- compas/geometry/surfaces/spherical.py +259 -0
- compas/geometry/surfaces/surface.py +689 -0
- compas/geometry/surfaces/toroidal.py +198 -0
- compas/geometry/transformation.py +554 -0
- compas/geometry/translation.py +104 -0
- compas/geometry/triangulation_delaunay.py +102 -0
- compas/geometry/triangulation_earclip.py +300 -0
- compas/geometry/trimesh_curvature.py +113 -0
- compas/geometry/trimesh_descent_numpy.py +26 -0
- compas/geometry/trimesh_geodistance.py +35 -0
- compas/geometry/trimesh_gradient_numpy.py +74 -0
- compas/geometry/trimesh_isolines.py +41 -0
- compas/geometry/trimesh_matrices.py +31 -0
- compas/geometry/trimesh_matrices_numpy.py +191 -0
- compas/geometry/trimesh_parametrisation.py +55 -0
- compas/geometry/trimesh_pull_points_numpy.py +216 -0
- compas/geometry/trimesh_remeshing.py +97 -0
- compas/geometry/trimesh_samplepoints_numpy.py +108 -0
- compas/geometry/trimesh_slicing.py +28 -0
- compas/geometry/trimesh_smoothing_numpy.py +34 -0
- compas/geometry/vector.py +889 -0
- compas/itertools.py +441 -0
- compas/linalg.py +634 -0
- compas/matrices.py +314 -0
- compas/plugins.py +488 -0
- compas/rpc/__init__.py +20 -0
- compas/rpc/__main__.py +77 -0
- compas/rpc/dispatcher.py +181 -0
- compas/rpc/errors.py +11 -0
- compas/rpc/proxy.py +437 -0
- compas/rpc/server.py +79 -0
- compas/rpc/services/__init__.py +0 -0
- compas/rpc/services/default.py +87 -0
- compas/rpc/services/watcher.py +43 -0
- compas/scene/__init__.py +56 -0
- compas/scene/assemblyobject.py +3 -0
- compas/scene/context.py +154 -0
- compas/scene/descriptors/__init__.py +0 -0
- compas/scene/descriptors/attribute.py +30 -0
- compas/scene/descriptors/color.py +91 -0
- compas/scene/descriptors/colordict.py +101 -0
- compas/scene/descriptors/protocol.py +12 -0
- compas/scene/exceptions.py +7 -0
- compas/scene/geometryobject.py +58 -0
- compas/scene/graphobject.py +173 -0
- compas/scene/meshobject.py +238 -0
- compas/scene/scene.py +144 -0
- compas/scene/sceneobject.py +253 -0
- compas/scene/volmeshobject.py +252 -0
- compas/tolerance.py +879 -0
- compas/topology/__init__.py +45 -0
- compas/topology/combinatorics.py +108 -0
- compas/topology/connectivity.py +129 -0
- compas/topology/orientation.py +204 -0
- compas/topology/traversal.py +567 -0
- compas/utilities/__init__.py +25 -0
- compas/utilities/azync.py +155 -0
- compas/utilities/datetime.py +40 -0
- compas/utilities/decorators.py +136 -0
- compas/utilities/remote.py +54 -0
- compas/utilities/ssh.py +169 -0
- compas-2.1.1.dist-info/AUTHORS.md +42 -0
- compas-2.1.1.dist-info/LICENSE +21 -0
- compas-2.1.1.dist-info/METADATA +132 -0
- compas-2.1.1.dist-info/RECORD +468 -0
- compas-2.1.1.dist-info/WHEEL +5 -0
- compas-2.1.1.dist-info/entry_points.txt +2 -0
- compas-2.1.1.dist-info/top_level.txt +4 -0
- compas_blender/__init__.py +250 -0
- compas_blender/collections.py +130 -0
- compas_blender/conversions/__init__.py +48 -0
- compas_blender/conversions/breps.py +0 -0
- compas_blender/conversions/colors.py +23 -0
- compas_blender/conversions/curves.py +125 -0
- compas_blender/conversions/geometry.py +161 -0
- compas_blender/conversions/meshes.py +148 -0
- compas_blender/conversions/surfaces.py +48 -0
- compas_blender/conversions/transformations.py +46 -0
- compas_blender/data.py +30 -0
- compas_blender/geometry/__init__.py +14 -0
- compas_blender/geometry/booleans.py +100 -0
- compas_blender/install.py +338 -0
- compas_blender/objects.py +326 -0
- compas_blender/print_python_path.py +18 -0
- compas_blender/scene/__init__.py +116 -0
- compas_blender/scene/boxobject.py +64 -0
- compas_blender/scene/capsuleobject.py +73 -0
- compas_blender/scene/circleobject.py +53 -0
- compas_blender/scene/coneobject.py +70 -0
- compas_blender/scene/curveobject.py +58 -0
- compas_blender/scene/cylinderobject.py +70 -0
- compas_blender/scene/frameobject.py +105 -0
- compas_blender/scene/graphobject.py +257 -0
- compas_blender/scene/lineobject.py +60 -0
- compas_blender/scene/meshobject.py +508 -0
- compas_blender/scene/planeobject.py +81 -0
- compas_blender/scene/pointcloudobject.py +67 -0
- compas_blender/scene/pointobject.py +71 -0
- compas_blender/scene/polygonobject.py +57 -0
- compas_blender/scene/polyhedronobject.py +57 -0
- compas_blender/scene/polylineobject.py +54 -0
- compas_blender/scene/sceneobject.py +249 -0
- compas_blender/scene/sphereobject.py +72 -0
- compas_blender/scene/surfaceobject.py +54 -0
- compas_blender/scene/torusobject.py +73 -0
- compas_blender/scene/vectorobject.py +69 -0
- compas_blender/scene/volmeshobject.py +475 -0
- compas_blender/utilities/__init__.py +38 -0
- compas_blender/utilities/drawing.py +768 -0
- compas_ghpython/__init__.py +124 -0
- compas_ghpython/components/Compas_FromJson/code.py +18 -0
- compas_ghpython/components/Compas_Info/code.py +15 -0
- compas_ghpython/components/Compas_RpcCall/code.py +31 -0
- compas_ghpython/components/Compas_ToJson/code.py +19 -0
- compas_ghpython/components/Compas_ToRhinoGeometry/code.py +15 -0
- compas_ghpython/components/__init__.py +99 -0
- compas_ghpython/install.py +29 -0
- compas_ghpython/scene/__init__.py +115 -0
- compas_ghpython/scene/boxobject.py +40 -0
- compas_ghpython/scene/brepobject.py +40 -0
- compas_ghpython/scene/capsuleobject.py +41 -0
- compas_ghpython/scene/circleobject.py +40 -0
- compas_ghpython/scene/coneobject.py +40 -0
- compas_ghpython/scene/curveobject.py +42 -0
- compas_ghpython/scene/cylinderobject.py +38 -0
- compas_ghpython/scene/ellipseobject.py +40 -0
- compas_ghpython/scene/frameobject.py +67 -0
- compas_ghpython/scene/graphobject.py +77 -0
- compas_ghpython/scene/lineobject.py +39 -0
- compas_ghpython/scene/meshobject.py +137 -0
- compas_ghpython/scene/planeobject.py +61 -0
- compas_ghpython/scene/pointobject.py +38 -0
- compas_ghpython/scene/polygonobject.py +48 -0
- compas_ghpython/scene/polyhedronobject.py +48 -0
- compas_ghpython/scene/polylineobject.py +39 -0
- compas_ghpython/scene/sceneobject.py +12 -0
- compas_ghpython/scene/sphereobject.py +39 -0
- compas_ghpython/scene/surfaceobject.py +42 -0
- compas_ghpython/scene/torusobject.py +39 -0
- compas_ghpython/scene/vectorobject.py +51 -0
- compas_ghpython/scene/volmeshobject.py +154 -0
- compas_ghpython/sets.py +83 -0
- compas_ghpython/timer.py +36 -0
- compas_ghpython/uninstall.py +31 -0
- compas_ghpython/utilities/__init__.py +33 -0
- compas_ghpython/utilities/drawing.py +457 -0
- compas_rhino/__init__.py +607 -0
- compas_rhino/conduits/__init__.py +16 -0
- compas_rhino/conduits/base.py +121 -0
- compas_rhino/conduits/faces.py +91 -0
- compas_rhino/conduits/labels.py +102 -0
- compas_rhino/conduits/lines.py +109 -0
- compas_rhino/conduits/points.py +111 -0
- compas_rhino/conversions/__init__.py +168 -0
- compas_rhino/conversions/breps.py +122 -0
- compas_rhino/conversions/curves.py +453 -0
- compas_rhino/conversions/docobjects.py +0 -0
- compas_rhino/conversions/exceptions.py +7 -0
- compas_rhino/conversions/extrusions.py +80 -0
- compas_rhino/conversions/geometry.py +187 -0
- compas_rhino/conversions/meshes.py +281 -0
- compas_rhino/conversions/shapes.py +291 -0
- compas_rhino/conversions/surfaces.py +355 -0
- compas_rhino/conversions/transformations.py +45 -0
- compas_rhino/geometry/__init__.py +44 -0
- compas_rhino/geometry/booleans.py +118 -0
- compas_rhino/geometry/brep/__init__.py +40 -0
- compas_rhino/geometry/brep/brep.py +554 -0
- compas_rhino/geometry/brep/builder.py +184 -0
- compas_rhino/geometry/brep/edge.py +202 -0
- compas_rhino/geometry/brep/face.py +285 -0
- compas_rhino/geometry/brep/loop.py +129 -0
- compas_rhino/geometry/brep/trim.py +99 -0
- compas_rhino/geometry/brep/vertex.py +76 -0
- compas_rhino/geometry/curves/__init__.py +43 -0
- compas_rhino/geometry/curves/curve.py +382 -0
- compas_rhino/geometry/curves/nurbs.py +298 -0
- compas_rhino/geometry/surfaces/__init__.py +50 -0
- compas_rhino/geometry/surfaces/nurbs.py +370 -0
- compas_rhino/geometry/surfaces/surface.py +407 -0
- compas_rhino/geometry/trimesh_curvature.py +344 -0
- compas_rhino/geometry/trimesh_slicing.py +65 -0
- compas_rhino/install.py +382 -0
- compas_rhino/install_plugin.py +169 -0
- compas_rhino/install_with_pip.py +20 -0
- compas_rhino/layers.py +347 -0
- compas_rhino/objects.py +1141 -0
- compas_rhino/print_python_path.py +18 -0
- compas_rhino/scene/__init__.py +123 -0
- compas_rhino/scene/boxobject.py +44 -0
- compas_rhino/scene/brepobject.py +41 -0
- compas_rhino/scene/capsuleobject.py +45 -0
- compas_rhino/scene/circleobject.py +43 -0
- compas_rhino/scene/coneobject.py +43 -0
- compas_rhino/scene/curveobject.py +43 -0
- compas_rhino/scene/cylinderobject.py +43 -0
- compas_rhino/scene/ellipseobject.py +44 -0
- compas_rhino/scene/frameobject.py +99 -0
- compas_rhino/scene/graphobject.py +364 -0
- compas_rhino/scene/helpers.py +33 -0
- compas_rhino/scene/lineobject.py +43 -0
- compas_rhino/scene/meshobject.py +673 -0
- compas_rhino/scene/planeobject.py +71 -0
- compas_rhino/scene/pointobject.py +43 -0
- compas_rhino/scene/polygonobject.py +45 -0
- compas_rhino/scene/polyhedronobject.py +45 -0
- compas_rhino/scene/polylineobject.py +43 -0
- compas_rhino/scene/sceneobject.py +123 -0
- compas_rhino/scene/sphereobject.py +43 -0
- compas_rhino/scene/surfaceobject.py +42 -0
- compas_rhino/scene/torusobject.py +43 -0
- compas_rhino/scene/vectorobject.py +49 -0
- compas_rhino/scene/volmeshobject.py +518 -0
- compas_rhino/ui.py +114 -0
- compas_rhino/uninstall.py +243 -0
- compas_rhino/uninstall_plugin.py +91 -0
- compas_rhino/utilities/__init__.py +37 -0
- compas_rhino/utilities/constructors.py +71 -0
- compas_rhino/utilities/drawing.py +1081 -0
compas/files/obj.py
ADDED
|
@@ -0,0 +1,680 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from collections import OrderedDict
|
|
6
|
+
from collections import defaultdict
|
|
7
|
+
|
|
8
|
+
import compas
|
|
9
|
+
from compas import _iotools
|
|
10
|
+
from compas.tolerance import TOL
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class OBJ(object):
|
|
14
|
+
"""Class for working with OBJ files.
|
|
15
|
+
|
|
16
|
+
Currently, reading is only supported for polygonal geometry.
|
|
17
|
+
Writing is only supported for meshes.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
filepath : path string | file-like object | URL string
|
|
22
|
+
A path, a file-like object or a URL pointing to a file.
|
|
23
|
+
precision : str, optional
|
|
24
|
+
A COMPAS precision specification.
|
|
25
|
+
|
|
26
|
+
Attributes
|
|
27
|
+
----------
|
|
28
|
+
reader : :class:`OBJReader`, read-only
|
|
29
|
+
A OBJ file reader.
|
|
30
|
+
parser : :class:`OBJParser`, read-only
|
|
31
|
+
A OBJ data parser.
|
|
32
|
+
vertices : list[list[float]], read-only
|
|
33
|
+
The vertices found in the parsed data.
|
|
34
|
+
lines : list[tuple[int, int]], read-only
|
|
35
|
+
The lines found in the parsed data, as vertex pairs.
|
|
36
|
+
faces : list[list[int]], read-only
|
|
37
|
+
The faces found in the parsed data, as lists of vertices.
|
|
38
|
+
objects : dict[str, tuple[list[list[float, float, float]], list[list[int]]]], read-only
|
|
39
|
+
The objects found in the parsed data, as a mapping between object names and tuples of lists of vertices and faces.
|
|
40
|
+
|
|
41
|
+
References
|
|
42
|
+
----------
|
|
43
|
+
* http://paulbourke.net/dataformats/obj/
|
|
44
|
+
|
|
45
|
+
Examples
|
|
46
|
+
--------
|
|
47
|
+
Reading and writing of a single mesh.
|
|
48
|
+
|
|
49
|
+
>>> from compas.datastructures import Mesh
|
|
50
|
+
>>> from compas.files import OBJ
|
|
51
|
+
|
|
52
|
+
Write mesh data to a file.
|
|
53
|
+
|
|
54
|
+
>>> mesh = Mesh.from_polyhedron(12)
|
|
55
|
+
>>> obj = OBJ("mesh.obj")
|
|
56
|
+
>>> obj.write(mesh)
|
|
57
|
+
|
|
58
|
+
Read mesh data from a file.
|
|
59
|
+
|
|
60
|
+
>>> obj = OBJ("mesh.obj")
|
|
61
|
+
>>> obj.read()
|
|
62
|
+
>>> mesh = Mesh.from_vertices_and_faces(obj.vertices, obj.faces)
|
|
63
|
+
|
|
64
|
+
Reading and writing of multiple meshes as separate objects in a single OBJ file.
|
|
65
|
+
|
|
66
|
+
>>> from compas.geometry import Pointcloud, Translation
|
|
67
|
+
>>> from compas.datastructures import Mesh
|
|
68
|
+
>>> from compas.files import OBJ
|
|
69
|
+
|
|
70
|
+
Write mesh data to a file.
|
|
71
|
+
|
|
72
|
+
>>> meshes = []
|
|
73
|
+
>>> for point in Pointcloud.from_bounds(10, 10, 10, 100):
|
|
74
|
+
... mesh = Mesh.from_polyhedron(12)
|
|
75
|
+
... mesh.transform(Translation.from_vector(point))
|
|
76
|
+
... meshes.append(mesh)
|
|
77
|
+
>>> obj = OBJ("meshes.obj")
|
|
78
|
+
>>> obj.write(meshes)
|
|
79
|
+
|
|
80
|
+
Read mesh data from a file.
|
|
81
|
+
|
|
82
|
+
>>> obj = OBJ("meshes.obj")
|
|
83
|
+
>>> obj.read()
|
|
84
|
+
>>> meshes = []
|
|
85
|
+
>>> for name in obj.objects:
|
|
86
|
+
... mesh = Mesh.from_vertices_and_faces(*obj.objects[name])
|
|
87
|
+
... mesh.name = name
|
|
88
|
+
... meshes.append(mesh)
|
|
89
|
+
|
|
90
|
+
"""
|
|
91
|
+
|
|
92
|
+
def __init__(self, filepath, precision=None):
|
|
93
|
+
self.filepath = filepath
|
|
94
|
+
self.precision = precision
|
|
95
|
+
self._is_parsed = False
|
|
96
|
+
self._reader = None
|
|
97
|
+
self._parser = None
|
|
98
|
+
self._writer = None
|
|
99
|
+
|
|
100
|
+
def read(self):
|
|
101
|
+
"""Read and parse the contents of the file.
|
|
102
|
+
|
|
103
|
+
Returns
|
|
104
|
+
-------
|
|
105
|
+
None
|
|
106
|
+
"""
|
|
107
|
+
self._reader = OBJReader(self.filepath)
|
|
108
|
+
self._parser = OBJParser(self._reader, precision=self.precision)
|
|
109
|
+
self._reader.open()
|
|
110
|
+
self._reader.pre()
|
|
111
|
+
self._reader.read()
|
|
112
|
+
self._reader.post()
|
|
113
|
+
self._parser.parse()
|
|
114
|
+
self._is_parsed = True
|
|
115
|
+
|
|
116
|
+
def write(self, mesh, unweld=False, **kwargs):
|
|
117
|
+
"""Write a mesh to the file.
|
|
118
|
+
|
|
119
|
+
Parameters
|
|
120
|
+
----------
|
|
121
|
+
mesh : :class:`compas.datastructures.Mesh`
|
|
122
|
+
The mesh.
|
|
123
|
+
unweld : bool, optional
|
|
124
|
+
Flag indicating that the vertices of the faces should be unwelded.
|
|
125
|
+
author : str, optional
|
|
126
|
+
The author name to include in the header.
|
|
127
|
+
email : str, optional
|
|
128
|
+
The email of the author to include in the header.
|
|
129
|
+
date : str, optional
|
|
130
|
+
The date to include in the header.
|
|
131
|
+
|
|
132
|
+
Returns
|
|
133
|
+
-------
|
|
134
|
+
None
|
|
135
|
+
|
|
136
|
+
"""
|
|
137
|
+
self._writer = OBJWriter(self.filepath, mesh, precision=self.precision, unweld=unweld, **kwargs)
|
|
138
|
+
self._writer.write()
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def reader(self):
|
|
142
|
+
if not self._is_parsed:
|
|
143
|
+
self.read()
|
|
144
|
+
return self._reader
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def parser(self):
|
|
148
|
+
if not self._is_parsed:
|
|
149
|
+
self.read()
|
|
150
|
+
return self._parser
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def vertices(self):
|
|
154
|
+
return self.parser.vertices
|
|
155
|
+
|
|
156
|
+
@property
|
|
157
|
+
def lines(self):
|
|
158
|
+
return self.parser.lines
|
|
159
|
+
|
|
160
|
+
@property
|
|
161
|
+
def faces(self):
|
|
162
|
+
return self.parser.faces
|
|
163
|
+
|
|
164
|
+
@property
|
|
165
|
+
def objects(self):
|
|
166
|
+
return self.parser.objects
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def groups(self):
|
|
170
|
+
return self.parser.groups
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
class OBJReader(object):
|
|
174
|
+
"""Class for reading raw geometric data from OBJ files.
|
|
175
|
+
|
|
176
|
+
Parameters
|
|
177
|
+
----------
|
|
178
|
+
filepath : path string | file-like object | URL string
|
|
179
|
+
A path, a file-like object or a URL pointing to a file.
|
|
180
|
+
|
|
181
|
+
Attributes
|
|
182
|
+
----------
|
|
183
|
+
vertices : list[list[float, float, float]]
|
|
184
|
+
List of lists of vertex coordinates.
|
|
185
|
+
weights : list[float]
|
|
186
|
+
List of vertex weights.
|
|
187
|
+
normals : list[list[float, float, float]]
|
|
188
|
+
List of lists of normal components.
|
|
189
|
+
points : list[int]
|
|
190
|
+
List of references to vertex coordinates.
|
|
191
|
+
lines : list[tuple[int, int]]
|
|
192
|
+
List of pairs of references to vertex coordinates.
|
|
193
|
+
faces : list[list[int]
|
|
194
|
+
List of lists of references to vertex coordinates.
|
|
195
|
+
groups : dict[str, tuple[list[int], list[list[int]]]]
|
|
196
|
+
Groups of mesh objects defined by their vertices and faces.
|
|
197
|
+
objects : dict[str, tuple[list[int], list[list[int]]]]
|
|
198
|
+
Named mesh objects defined by their vertices and faces.
|
|
199
|
+
|
|
200
|
+
"""
|
|
201
|
+
|
|
202
|
+
def __init__(self, filepath):
|
|
203
|
+
self.filepath = filepath
|
|
204
|
+
self.content = None
|
|
205
|
+
# vertex data
|
|
206
|
+
self.vertices = []
|
|
207
|
+
self.weights = []
|
|
208
|
+
self.textures = []
|
|
209
|
+
self.normals = []
|
|
210
|
+
# polygonal geometry
|
|
211
|
+
self.points = []
|
|
212
|
+
self.lines = []
|
|
213
|
+
self.faces = []
|
|
214
|
+
# free-form geometry
|
|
215
|
+
# self.curves = []
|
|
216
|
+
# self.curves2 = []
|
|
217
|
+
# self.surfaces = []
|
|
218
|
+
# free-form attributes
|
|
219
|
+
# self.deg = None
|
|
220
|
+
# self.bmat = None
|
|
221
|
+
# self.step = None
|
|
222
|
+
# self.cstype = None
|
|
223
|
+
# free-form statements
|
|
224
|
+
# parm, trim, hole, scrv, sp, end
|
|
225
|
+
# grouping
|
|
226
|
+
self.groups = defaultdict(list)
|
|
227
|
+
self.objects = defaultdict(list)
|
|
228
|
+
self.group = None
|
|
229
|
+
self.object = None
|
|
230
|
+
|
|
231
|
+
def open(self):
|
|
232
|
+
"""Open the file and read its contents.
|
|
233
|
+
|
|
234
|
+
Returns
|
|
235
|
+
-------
|
|
236
|
+
None
|
|
237
|
+
|
|
238
|
+
"""
|
|
239
|
+
with _iotools.open_file(self.filepath, "r") as f:
|
|
240
|
+
self.content = f.readlines()
|
|
241
|
+
|
|
242
|
+
def pre(self):
|
|
243
|
+
"""Pre-process the contents.
|
|
244
|
+
|
|
245
|
+
Returns
|
|
246
|
+
-------
|
|
247
|
+
None
|
|
248
|
+
|
|
249
|
+
"""
|
|
250
|
+
lines = []
|
|
251
|
+
is_continuation = False
|
|
252
|
+
needs_decode = None
|
|
253
|
+
|
|
254
|
+
for line in self.content:
|
|
255
|
+
# Check this only one time
|
|
256
|
+
if needs_decode is None:
|
|
257
|
+
needs_decode = hasattr(line, "decode")
|
|
258
|
+
if needs_decode:
|
|
259
|
+
line = line.decode("utf-8")
|
|
260
|
+
line = line.rstrip()
|
|
261
|
+
if not line:
|
|
262
|
+
continue
|
|
263
|
+
if is_continuation:
|
|
264
|
+
lines[-1] = lines[-1][:-2] + line
|
|
265
|
+
else:
|
|
266
|
+
lines.append(line)
|
|
267
|
+
if line[-1] == "\\":
|
|
268
|
+
is_continuation = True
|
|
269
|
+
else:
|
|
270
|
+
is_continuation = False
|
|
271
|
+
self.content = iter(lines)
|
|
272
|
+
|
|
273
|
+
def post(self):
|
|
274
|
+
"""Post-process the contents.
|
|
275
|
+
|
|
276
|
+
Returns
|
|
277
|
+
-------
|
|
278
|
+
None
|
|
279
|
+
|
|
280
|
+
"""
|
|
281
|
+
pass
|
|
282
|
+
|
|
283
|
+
def read(self):
|
|
284
|
+
"""Read the contents of the file, line by line.
|
|
285
|
+
|
|
286
|
+
Every line is split into a *head* and a *tail*.
|
|
287
|
+
The *head* determines the meaning of the data found in *tail*.
|
|
288
|
+
|
|
289
|
+
* ``#``: comment
|
|
290
|
+
* ``v``: vertex coordinates
|
|
291
|
+
* ``vt``: vertex texture
|
|
292
|
+
* ``vn``: vertex normal
|
|
293
|
+
* ``vp``: parameter vertex
|
|
294
|
+
* ``p``: point
|
|
295
|
+
* ``l``: line
|
|
296
|
+
* ``f``: face
|
|
297
|
+
* ``deg``: freeform attribute *degree*
|
|
298
|
+
* ``bmat``: freeform attribute *basis matrix*
|
|
299
|
+
* ``step``: freeform attribute *step size*
|
|
300
|
+
* ``cstype``: freeform attribute *curve or surface type*
|
|
301
|
+
* ``o``: start of named object
|
|
302
|
+
* ``g``: start of a named group
|
|
303
|
+
|
|
304
|
+
Returns
|
|
305
|
+
-------
|
|
306
|
+
None
|
|
307
|
+
|
|
308
|
+
"""
|
|
309
|
+
if not self.content:
|
|
310
|
+
return
|
|
311
|
+
for line in self.content:
|
|
312
|
+
parts = line.split()
|
|
313
|
+
if not parts:
|
|
314
|
+
continue
|
|
315
|
+
head = parts[0]
|
|
316
|
+
tail = parts[1:]
|
|
317
|
+
if head == "#":
|
|
318
|
+
self._read_comment(tail)
|
|
319
|
+
continue
|
|
320
|
+
if head == "v":
|
|
321
|
+
self._read_vertex_coordinates(tail)
|
|
322
|
+
continue
|
|
323
|
+
if head == "vt":
|
|
324
|
+
self._read_vertex_texture(tail)
|
|
325
|
+
continue
|
|
326
|
+
if head == "vn":
|
|
327
|
+
self._read_vertex_normal(tail)
|
|
328
|
+
continue
|
|
329
|
+
if head == "vp":
|
|
330
|
+
self._read_parameter_vertex(tail)
|
|
331
|
+
continue
|
|
332
|
+
if head in ("p", "l", "f"):
|
|
333
|
+
self._read_polygonal_geometry(head, tail)
|
|
334
|
+
continue
|
|
335
|
+
if head in ("deg", "bmat", "step", "cstype"):
|
|
336
|
+
self._read_freeform_attribute(head, tail)
|
|
337
|
+
continue
|
|
338
|
+
if head in ("curv", "curv2", "surf"):
|
|
339
|
+
self._read_freeform_geometry(head, tail)
|
|
340
|
+
continue
|
|
341
|
+
if head in ("parm", "trim", "hole", "scrv", "sp", "end"):
|
|
342
|
+
self._read_freeform_statement(head, tail)
|
|
343
|
+
continue
|
|
344
|
+
if head in ("g", "s", "mg", "o"):
|
|
345
|
+
self._read_grouping(head, tail)
|
|
346
|
+
continue
|
|
347
|
+
|
|
348
|
+
def _read_comment(self, data):
|
|
349
|
+
"""Read a comment.
|
|
350
|
+
|
|
351
|
+
Comments start with ``#``.
|
|
352
|
+
|
|
353
|
+
"""
|
|
354
|
+
pass
|
|
355
|
+
|
|
356
|
+
def _read_vertex_coordinates(self, data):
|
|
357
|
+
"""Read the coordinates of a vertex.
|
|
358
|
+
|
|
359
|
+
Two types of formats are possible:
|
|
360
|
+
|
|
361
|
+
* x y z
|
|
362
|
+
* x y z w
|
|
363
|
+
|
|
364
|
+
"""
|
|
365
|
+
if len(data) == 3:
|
|
366
|
+
self.vertices.append([float(x) for x in data])
|
|
367
|
+
self.weights.append(1.0)
|
|
368
|
+
return
|
|
369
|
+
if len(data) == 4:
|
|
370
|
+
self.vertices.append([float(x) for x in data[:3]])
|
|
371
|
+
self.weights.append(float(data[3]))
|
|
372
|
+
|
|
373
|
+
def _read_vertex_texture(self, data):
|
|
374
|
+
pass
|
|
375
|
+
|
|
376
|
+
def _read_vertex_normal(self, data):
|
|
377
|
+
pass
|
|
378
|
+
|
|
379
|
+
def _read_parameter_vertex(self, data):
|
|
380
|
+
pass
|
|
381
|
+
|
|
382
|
+
def _read_polygonal_geometry(self, name, data):
|
|
383
|
+
# point
|
|
384
|
+
if name == "p":
|
|
385
|
+
self.points.append(int(data[0]) - 1)
|
|
386
|
+
ref = "p", len(self.points) - 1
|
|
387
|
+
self.groups[self.group].append(ref)
|
|
388
|
+
self.objects[self.object].append(ref)
|
|
389
|
+
# line
|
|
390
|
+
elif name == "l":
|
|
391
|
+
if len(data) < 2:
|
|
392
|
+
return
|
|
393
|
+
self.lines.append([int(i) - 1 for i in data])
|
|
394
|
+
ref = "l", len(self.lines) - 1
|
|
395
|
+
self.groups[self.group].append(ref)
|
|
396
|
+
self.objects[self.object].append(ref)
|
|
397
|
+
# face
|
|
398
|
+
elif name == "f":
|
|
399
|
+
if len(data) < 3:
|
|
400
|
+
return
|
|
401
|
+
face = []
|
|
402
|
+
for d in data:
|
|
403
|
+
parts = d.split("/")
|
|
404
|
+
i = int(parts[0]) - 1
|
|
405
|
+
face.append(i)
|
|
406
|
+
self.faces.append(face)
|
|
407
|
+
ref = "f", len(self.faces) - 1
|
|
408
|
+
self.groups[self.group].append(ref)
|
|
409
|
+
self.objects[self.object].append(ref)
|
|
410
|
+
|
|
411
|
+
def _read_freeform_attribute(self, name, data):
|
|
412
|
+
if name == "deg":
|
|
413
|
+
self.deg = [int(i) for i in data]
|
|
414
|
+
return
|
|
415
|
+
if name == "bmat":
|
|
416
|
+
return
|
|
417
|
+
if name == "step":
|
|
418
|
+
return
|
|
419
|
+
if name == "cstype":
|
|
420
|
+
self.cstype = data
|
|
421
|
+
return
|
|
422
|
+
|
|
423
|
+
def _read_freeform_geometry(self, name, data):
|
|
424
|
+
# curv u0 u1 v1 v2 ...
|
|
425
|
+
# u0: starting parameter value for the curve
|
|
426
|
+
# u1: ending parameter value for the curve
|
|
427
|
+
# v1: vertex reference number for control point
|
|
428
|
+
# v2: vertex reference number for control point
|
|
429
|
+
# ...
|
|
430
|
+
if name == "curv":
|
|
431
|
+
if self.deg[0] == 1:
|
|
432
|
+
if len(data) == 4:
|
|
433
|
+
self.lines.append((int(data[2]) - 1, int(data[3]) - 1))
|
|
434
|
+
ref = "l", len(self.lines) - 1
|
|
435
|
+
self.groups[self.group].append(ref)
|
|
436
|
+
self.objects[self.object].append(ref)
|
|
437
|
+
return
|
|
438
|
+
if len(data) > 4:
|
|
439
|
+
self.lines.append([int(d) - 1 for d in data[2:]])
|
|
440
|
+
ref = "l", len(self.lines) - 1
|
|
441
|
+
self.groups[self.group].append(ref)
|
|
442
|
+
self.objects[self.object].append(ref)
|
|
443
|
+
return
|
|
444
|
+
|
|
445
|
+
def _read_freeform_statement(self, name, data):
|
|
446
|
+
pass
|
|
447
|
+
|
|
448
|
+
def _read_grouping(self, name, data):
|
|
449
|
+
if name == "o":
|
|
450
|
+
self.object = " ".join(data)
|
|
451
|
+
self.objects[self.object] = []
|
|
452
|
+
return
|
|
453
|
+
if name == "g":
|
|
454
|
+
self.group = " ".join(data)
|
|
455
|
+
self.groups[self.group] = []
|
|
456
|
+
self.objects[self.object].append(("g", self.group))
|
|
457
|
+
return
|
|
458
|
+
|
|
459
|
+
|
|
460
|
+
class OBJParser(object):
|
|
461
|
+
"""Class for parsing data from a OBJ file.
|
|
462
|
+
|
|
463
|
+
The parser converts the raw geometric data of the file
|
|
464
|
+
into corresponding COMPAS geometry objects and data structures.
|
|
465
|
+
|
|
466
|
+
Parameters
|
|
467
|
+
----------
|
|
468
|
+
reader : :class:`OBJReader`
|
|
469
|
+
A OBJ file reader.
|
|
470
|
+
precision : int, optional
|
|
471
|
+
Precision for converting numbers to strings.
|
|
472
|
+
Default is :attr:`TOL.precision`.
|
|
473
|
+
|
|
474
|
+
Attributes
|
|
475
|
+
----------
|
|
476
|
+
reader : :class:`OBJReader`
|
|
477
|
+
An OBJ file reader.
|
|
478
|
+
vertices : list[list[float, float, float]]
|
|
479
|
+
List of lists of parsed vertex coordinates.
|
|
480
|
+
Parsed vertices are unique up to the specified precision.
|
|
481
|
+
points : list[int]
|
|
482
|
+
List of references to parsed vertex coordinates.
|
|
483
|
+
lines : list[tuple[int, int]]
|
|
484
|
+
List of pairs of references to parsed vertex coordinates.
|
|
485
|
+
polylines : list[list[int]
|
|
486
|
+
List of lists of references to parsed vertex coordinates.
|
|
487
|
+
faces : list[list[int]
|
|
488
|
+
List of lists of references to parsed vertex coordinates.
|
|
489
|
+
groups : dict[str, tuple[list[int], list[list[int]]]]
|
|
490
|
+
Groups of mesh objects defined by their parsed vertices and faces.
|
|
491
|
+
objects : dict[str, tuple[list[int], list[list[int]]]]
|
|
492
|
+
Named mesh objects defined by their parsed vertices and faces.
|
|
493
|
+
|
|
494
|
+
"""
|
|
495
|
+
|
|
496
|
+
def __init__(self, reader, precision=None):
|
|
497
|
+
self.precision = precision
|
|
498
|
+
self.reader = reader
|
|
499
|
+
self.vertices = None
|
|
500
|
+
# self.weights = None
|
|
501
|
+
# self.textures = None
|
|
502
|
+
# self.normals = None
|
|
503
|
+
self.points = None
|
|
504
|
+
self.lines = None
|
|
505
|
+
self.polylines = None
|
|
506
|
+
self.faces = None
|
|
507
|
+
# self.curves = None
|
|
508
|
+
# self.curves2 = None
|
|
509
|
+
# self.surfaces = None
|
|
510
|
+
self.groups = None
|
|
511
|
+
self.objects = None
|
|
512
|
+
|
|
513
|
+
def parse(self):
|
|
514
|
+
"""Parse the the data found by the reader.
|
|
515
|
+
|
|
516
|
+
Returns
|
|
517
|
+
-------
|
|
518
|
+
None
|
|
519
|
+
|
|
520
|
+
"""
|
|
521
|
+
index_key = OrderedDict()
|
|
522
|
+
vertex = OrderedDict()
|
|
523
|
+
|
|
524
|
+
for i, xyz in enumerate(iter(self.reader.vertices)):
|
|
525
|
+
key = TOL.geometric_key(xyz, self.precision)
|
|
526
|
+
index_key[i] = key
|
|
527
|
+
vertex[key] = xyz
|
|
528
|
+
|
|
529
|
+
vertex_index = {key: index for index, key in enumerate(vertex)}
|
|
530
|
+
index_index = {index: vertex_index[key] for index, key in iter(index_key.items())}
|
|
531
|
+
|
|
532
|
+
self.vertices = [xyz for xyz in iter(vertex.values())]
|
|
533
|
+
self.points = [index_index[index] for index in self.reader.points]
|
|
534
|
+
self.lines = [[index_index[index] for index in line] for line in self.reader.lines if len(line) == 2]
|
|
535
|
+
self.polylines = [[index_index[index] for index in line] for line in self.reader.lines if len(line) > 2]
|
|
536
|
+
self.faces = [[index_index[index] for index in face] for face in self.reader.faces]
|
|
537
|
+
self.groups = self.reader.groups
|
|
538
|
+
self.objects = {}
|
|
539
|
+
for name in self.reader.objects:
|
|
540
|
+
faces = []
|
|
541
|
+
for item in self.reader.objects[name]:
|
|
542
|
+
if item[0] == "f":
|
|
543
|
+
faces.append(self.faces[item[1]])
|
|
544
|
+
vertices = {}
|
|
545
|
+
for face in faces:
|
|
546
|
+
for vertex in face:
|
|
547
|
+
vertices[vertex] = self.vertices[vertex]
|
|
548
|
+
self.objects[name] = vertices, faces
|
|
549
|
+
|
|
550
|
+
|
|
551
|
+
class OBJWriter(object):
|
|
552
|
+
"""Class for writing geometric data to a OBJ file.
|
|
553
|
+
|
|
554
|
+
Parameters
|
|
555
|
+
----------
|
|
556
|
+
filepath : path string | file-like object | URL string
|
|
557
|
+
A path, a file-like object or a URL pointing to a file.
|
|
558
|
+
meshes : list[:class:`compas.datastructures.Mesh`]
|
|
559
|
+
list of meshes to write to the file.
|
|
560
|
+
precision : str, optional
|
|
561
|
+
COMPAS precision specification for parsing geometric data.
|
|
562
|
+
unweld : bool, optional
|
|
563
|
+
Flag indicating that the face vertices should be unwelded.
|
|
564
|
+
author : str, optional
|
|
565
|
+
The author name to include in the header.
|
|
566
|
+
email : str, optional
|
|
567
|
+
The email of the author to include in the header.
|
|
568
|
+
date : str, optional
|
|
569
|
+
The date to include in the header.
|
|
570
|
+
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
def __init__(
|
|
574
|
+
self,
|
|
575
|
+
filepath,
|
|
576
|
+
meshes,
|
|
577
|
+
precision=None,
|
|
578
|
+
unweld=False,
|
|
579
|
+
author=None,
|
|
580
|
+
email=None,
|
|
581
|
+
date=None,
|
|
582
|
+
):
|
|
583
|
+
self.filepath = filepath
|
|
584
|
+
self.meshes = meshes if isinstance(meshes, (list, tuple)) else [meshes]
|
|
585
|
+
self.author = author
|
|
586
|
+
self.email = email
|
|
587
|
+
self.date = date
|
|
588
|
+
self.precision = precision or TOL.precision
|
|
589
|
+
self.unweld = unweld
|
|
590
|
+
self.v = sum(mesh.number_of_vertices() for mesh in self.meshes)
|
|
591
|
+
self.f = sum(mesh.number_of_faces() for mesh in self.meshes)
|
|
592
|
+
self.e = sum(mesh.number_of_edges() for mesh in self.meshes)
|
|
593
|
+
self._v = 1
|
|
594
|
+
self.file = None
|
|
595
|
+
|
|
596
|
+
def write(self):
|
|
597
|
+
"""Write the meshes to the file.
|
|
598
|
+
|
|
599
|
+
Returns
|
|
600
|
+
-------
|
|
601
|
+
None
|
|
602
|
+
|
|
603
|
+
"""
|
|
604
|
+
with _iotools.open_file(self.filepath, "w") as self.file:
|
|
605
|
+
self._write_header()
|
|
606
|
+
self._write_meshes()
|
|
607
|
+
|
|
608
|
+
def _write_header(self):
|
|
609
|
+
if not self.file:
|
|
610
|
+
return
|
|
611
|
+
self.file.write("# OBJ\n")
|
|
612
|
+
self.file.write("# COMPAS\n")
|
|
613
|
+
self.file.write("# version: {}\n".format(compas.__version__))
|
|
614
|
+
self.file.write("# precision: {}\n".format(self.precision))
|
|
615
|
+
self.file.write("# V F E: {} {} {}\n".format(self.v, self.f, self.e))
|
|
616
|
+
if self.author:
|
|
617
|
+
self.file.write("# author: {}\n".format(self.author))
|
|
618
|
+
if self.email:
|
|
619
|
+
self.file.write("# email: {}\n".format(self.email))
|
|
620
|
+
if self.date:
|
|
621
|
+
self.file.write("# date: {}\n".format(self.date))
|
|
622
|
+
self.file.write("\n")
|
|
623
|
+
|
|
624
|
+
def _write_meshes(self):
|
|
625
|
+
if not self.file:
|
|
626
|
+
return
|
|
627
|
+
for index, mesh in enumerate(self.meshes):
|
|
628
|
+
name = mesh.name
|
|
629
|
+
if name == "Mesh":
|
|
630
|
+
name = "Mesh {}".format(index)
|
|
631
|
+
self.file.write("o {}\n".format(name))
|
|
632
|
+
if self.unweld:
|
|
633
|
+
self._write_vertices_and_faces(mesh)
|
|
634
|
+
else:
|
|
635
|
+
self._write_vertices(mesh)
|
|
636
|
+
self._write_faces(mesh)
|
|
637
|
+
self._v += mesh.number_of_vertices()
|
|
638
|
+
|
|
639
|
+
def _write_vertices(self, mesh):
|
|
640
|
+
if not self.file:
|
|
641
|
+
return
|
|
642
|
+
for key in mesh.vertices():
|
|
643
|
+
x, y, z = mesh.vertex_coordinates(key)
|
|
644
|
+
self.file.write(
|
|
645
|
+
"v {0} {1} {2}\n".format(
|
|
646
|
+
TOL.format_number(x, self.precision),
|
|
647
|
+
TOL.format_number(y, self.precision),
|
|
648
|
+
TOL.format_number(z, self.precision),
|
|
649
|
+
)
|
|
650
|
+
)
|
|
651
|
+
|
|
652
|
+
def _write_faces(self, mesh):
|
|
653
|
+
if not self.file:
|
|
654
|
+
return
|
|
655
|
+
vertex_index = mesh.vertex_index()
|
|
656
|
+
for face in mesh.faces():
|
|
657
|
+
vertices = mesh.face_vertices(face)
|
|
658
|
+
vertices = [vertex_index[key] + self._v for key in vertices]
|
|
659
|
+
vertices_str = " ".join([str(index) for index in vertices])
|
|
660
|
+
self.file.write("f {0}\n".format(vertices_str))
|
|
661
|
+
|
|
662
|
+
def _write_vertices_and_faces(self, mesh):
|
|
663
|
+
if not self.file:
|
|
664
|
+
return
|
|
665
|
+
for face in mesh.faces():
|
|
666
|
+
vertices = mesh.face_vertices(face)
|
|
667
|
+
indices = []
|
|
668
|
+
for vertex in vertices:
|
|
669
|
+
x, y, z = mesh.vertex_coordinates(vertex)
|
|
670
|
+
self.file.write(
|
|
671
|
+
"v {0} {1} {2}\n".format(
|
|
672
|
+
TOL.format_number(x, self.precision),
|
|
673
|
+
TOL.format_number(y, self.precision),
|
|
674
|
+
TOL.format_number(z, self.precision),
|
|
675
|
+
)
|
|
676
|
+
)
|
|
677
|
+
indices.append(self._v)
|
|
678
|
+
self._v += 1
|
|
679
|
+
indices_str = " ".join([str(i) for i in indices])
|
|
680
|
+
self.file.write("f {0}\n".format(indices_str))
|