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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from compas.files.gltf.data_classes import AnimationData
|
|
6
|
+
from compas.files.gltf.data_classes import AnimationSamplerData
|
|
7
|
+
from compas.files.gltf.data_classes import CameraData
|
|
8
|
+
from compas.files.gltf.data_classes import ChannelData
|
|
9
|
+
from compas.files.gltf.data_classes import MaterialData
|
|
10
|
+
from compas.files.gltf.data_classes import PrimitiveData
|
|
11
|
+
from compas.files.gltf.data_classes import SamplerData
|
|
12
|
+
from compas.files.gltf.data_classes import SkinData
|
|
13
|
+
from compas.files.gltf.data_classes import TextureData
|
|
14
|
+
from compas.files.gltf.gltf_content import GLTFContent
|
|
15
|
+
from compas.files.gltf.gltf_mesh import GLTFMesh
|
|
16
|
+
from compas.files.gltf.gltf_node import GLTFNode
|
|
17
|
+
from compas.files.gltf.gltf_scene import GLTFScene
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class GLTFParser(object):
|
|
21
|
+
"""Parse the contents of the reader into a GLTFContent object.
|
|
22
|
+
|
|
23
|
+
Parameters
|
|
24
|
+
----------
|
|
25
|
+
reader : :class:`compas.files.GLTFReader`
|
|
26
|
+
|
|
27
|
+
Attributes
|
|
28
|
+
----------
|
|
29
|
+
reader : :class:`compas.files.GLTFReader`
|
|
30
|
+
content : :class:`compas.files.GLTFContent`
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, reader):
|
|
34
|
+
self.reader = reader
|
|
35
|
+
self.content = GLTFContent()
|
|
36
|
+
|
|
37
|
+
self.parse()
|
|
38
|
+
|
|
39
|
+
def parse(self):
|
|
40
|
+
self.content.default_scene_key = self._get_default_scene()
|
|
41
|
+
self.content.extras = self._get_extras()
|
|
42
|
+
self.content.extensions = self._get_extensions()
|
|
43
|
+
|
|
44
|
+
self.content.images = {key: image_data for key, image_data in enumerate(self.reader.image_data)}
|
|
45
|
+
self.content.samplers = {key: SamplerData.from_data(sampler) for key, sampler in enumerate(self.reader.json.get("samplers", []))}
|
|
46
|
+
self.content.textures = {key: TextureData.from_data(texture) for key, texture in enumerate(self.reader.json.get("textures", []))}
|
|
47
|
+
self.content.materials = {key: MaterialData.from_data(material) for key, material in enumerate(self.reader.json.get("materials", []))}
|
|
48
|
+
self.content.cameras = {key: CameraData.from_data(camera) for key, camera in enumerate(self.reader.json.get("cameras", []))}
|
|
49
|
+
self.content.skins = {key: SkinData.from_data(skin, self.reader.data[skin["inverseBindMatrices"]]) for key, skin in enumerate(self.reader.json.get("skins", []))}
|
|
50
|
+
self.content.animations = {key: self._get_animation_data(animation) for key, animation in enumerate(self.reader.json.get("animations", []))}
|
|
51
|
+
|
|
52
|
+
for mesh in self.reader.json.get("meshes", []):
|
|
53
|
+
self._add_gltf_mesh(mesh)
|
|
54
|
+
for node in self.reader.json.get("nodes", []):
|
|
55
|
+
self._add_gltf_node(node)
|
|
56
|
+
for scene in self.reader.json.get("scenes", []):
|
|
57
|
+
self._add_gltf_scene(scene)
|
|
58
|
+
|
|
59
|
+
self.content.update_node_transforms_and_positions()
|
|
60
|
+
|
|
61
|
+
def _get_animation_data(self, animation):
|
|
62
|
+
sampler_data_dict = {}
|
|
63
|
+
for index, sampler in enumerate(animation["samplers"]):
|
|
64
|
+
input_ = self.reader.data[sampler["input"]]
|
|
65
|
+
output = self.reader.data[sampler["output"]]
|
|
66
|
+
sampler_data_dict[index] = AnimationSamplerData.from_data(sampler, input_, output)
|
|
67
|
+
channel_data_list = [ChannelData.from_data(channel) for channel in animation["channels"]]
|
|
68
|
+
return AnimationData.from_data(animation, channel_data_list, sampler_data_dict)
|
|
69
|
+
|
|
70
|
+
def _get_extras(self):
|
|
71
|
+
return self.reader.json.get("extras")
|
|
72
|
+
|
|
73
|
+
def _get_default_scene(self):
|
|
74
|
+
return self.reader.json.get("scene")
|
|
75
|
+
|
|
76
|
+
def _get_extensions(self):
|
|
77
|
+
return self.reader.json.get("extensions")
|
|
78
|
+
|
|
79
|
+
def _add_gltf_scene(self, scene):
|
|
80
|
+
GLTFScene.from_data(scene, self.content)
|
|
81
|
+
|
|
82
|
+
def _add_gltf_node(self, node):
|
|
83
|
+
GLTFNode.from_data(node, self.content)
|
|
84
|
+
|
|
85
|
+
def _add_gltf_mesh(self, mesh):
|
|
86
|
+
primitive_data_list = []
|
|
87
|
+
for primitive in mesh["primitives"]:
|
|
88
|
+
if "POSITION" not in primitive["attributes"]:
|
|
89
|
+
continue
|
|
90
|
+
|
|
91
|
+
attributes = {}
|
|
92
|
+
for attr, attr_accessor_index in primitive["attributes"].items():
|
|
93
|
+
attributes[attr] = self.reader.data[attr_accessor_index]
|
|
94
|
+
|
|
95
|
+
indices = self._get_indices(primitive, len(attributes["POSITION"]))
|
|
96
|
+
|
|
97
|
+
target_list = []
|
|
98
|
+
for target in primitive.get("targets", []):
|
|
99
|
+
target_data = {attr: self.reader.data[accessor_index] for attr, accessor_index in target.items()}
|
|
100
|
+
target_list.append(target_data)
|
|
101
|
+
|
|
102
|
+
primitive_data = PrimitiveData.from_data(primitive, attributes, indices, target_list)
|
|
103
|
+
|
|
104
|
+
primitive_data_list.append(primitive_data)
|
|
105
|
+
|
|
106
|
+
GLTFMesh.from_data(mesh, self.content, primitive_data_list)
|
|
107
|
+
|
|
108
|
+
def _get_indices(self, primitive, num_vertices):
|
|
109
|
+
if "indices" not in primitive:
|
|
110
|
+
return self.get_generic_indices(num_vertices)
|
|
111
|
+
indices_accessor_index = primitive["indices"]
|
|
112
|
+
return self.reader.data[indices_accessor_index]
|
|
113
|
+
|
|
114
|
+
def get_generic_indices(self, num_vertices):
|
|
115
|
+
return list(range(num_vertices))
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
import base64
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import re
|
|
9
|
+
import struct
|
|
10
|
+
|
|
11
|
+
from compas.files.gltf.constants import COMPONENT_TYPE_BYTE
|
|
12
|
+
from compas.files.gltf.constants import COMPONENT_TYPE_ENUM
|
|
13
|
+
from compas.files.gltf.constants import COMPONENT_TYPE_SHORT
|
|
14
|
+
from compas.files.gltf.constants import COMPONENT_TYPE_UNSIGNED_BYTE
|
|
15
|
+
from compas.files.gltf.constants import COMPONENT_TYPE_UNSIGNED_SHORT
|
|
16
|
+
from compas.files.gltf.constants import NUM_COMPONENTS_BY_TYPE_ENUM
|
|
17
|
+
from compas.files.gltf.data_classes import ImageData
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class GLTFReader(object):
|
|
21
|
+
"""Read the contents of a *glTF* or *glb* version 2 file using the json library.
|
|
22
|
+
Uses ideas from Khronos Group's glTF-Blender-IO.
|
|
23
|
+
Caution: Extensions are minimally supported and their data may be lost.
|
|
24
|
+
|
|
25
|
+
Parameters
|
|
26
|
+
----------
|
|
27
|
+
filepath: str
|
|
28
|
+
Path to the file.
|
|
29
|
+
|
|
30
|
+
Attributes
|
|
31
|
+
----------
|
|
32
|
+
filepath : str
|
|
33
|
+
String containing the path to the glTF.
|
|
34
|
+
json : dict
|
|
35
|
+
Dictionary object containing the contents of the glTF.
|
|
36
|
+
data : list
|
|
37
|
+
List of lists containing data read from binary files.
|
|
38
|
+
image_data : list
|
|
39
|
+
List containing image data.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
def __init__(self, filepath):
|
|
43
|
+
self.filepath = filepath
|
|
44
|
+
|
|
45
|
+
self.json = None
|
|
46
|
+
self.data = []
|
|
47
|
+
self.image_data = []
|
|
48
|
+
|
|
49
|
+
self._bin_content = None
|
|
50
|
+
self._glb_buffer = None
|
|
51
|
+
self._buffers = {}
|
|
52
|
+
|
|
53
|
+
self.read()
|
|
54
|
+
|
|
55
|
+
def read(self):
|
|
56
|
+
with open(self.filepath, "rb") as f:
|
|
57
|
+
self._bin_content = self._get_memoryview(f.read())
|
|
58
|
+
|
|
59
|
+
is_glb = self._bin_content[:4] == b"glTF"
|
|
60
|
+
|
|
61
|
+
if not is_glb:
|
|
62
|
+
content = self._bin_content.tobytes().decode("utf-8")
|
|
63
|
+
self.json = json.loads(content)
|
|
64
|
+
else:
|
|
65
|
+
self._load_from_glb()
|
|
66
|
+
|
|
67
|
+
self._release_buffer(self._bin_content)
|
|
68
|
+
self._bin_content = None
|
|
69
|
+
|
|
70
|
+
self._check_version()
|
|
71
|
+
|
|
72
|
+
if self.json:
|
|
73
|
+
for accessor in self.json.get("accessors", []):
|
|
74
|
+
accessor_data = self._access_data(accessor)
|
|
75
|
+
self.data.append(accessor_data)
|
|
76
|
+
|
|
77
|
+
for image in self.json.get("images", []):
|
|
78
|
+
mime_type = self.get_mime_type(image.get("uri"))
|
|
79
|
+
data = None
|
|
80
|
+
if "bufferView" in image:
|
|
81
|
+
data = self._get_attr_data(image, "bufferView")
|
|
82
|
+
if "uri" in image and self.is_data_uri(image["uri"]):
|
|
83
|
+
data = base64.b64decode(self.get_data_uri_data(image["uri"]))
|
|
84
|
+
|
|
85
|
+
image_data = ImageData.from_data(image, data, mime_type)
|
|
86
|
+
self.image_data.append(image_data)
|
|
87
|
+
|
|
88
|
+
self._release_buffers()
|
|
89
|
+
|
|
90
|
+
def _load_from_glb(self):
|
|
91
|
+
header = self._unpack_content("<4sII")
|
|
92
|
+
file_size = header[2]
|
|
93
|
+
|
|
94
|
+
if file_size != len(self._bin_content):
|
|
95
|
+
raise Exception("Bad glTF. File size does not match.")
|
|
96
|
+
|
|
97
|
+
offset = 12
|
|
98
|
+
|
|
99
|
+
# load json
|
|
100
|
+
type_, _length, json_bytes, offset = self._load_chunk(offset)
|
|
101
|
+
if type_ != b"JSON":
|
|
102
|
+
raise Exception("Bad glTF. First chunk not in JSON format")
|
|
103
|
+
json_str = json_bytes.tobytes().decode("utf-8")
|
|
104
|
+
self.json = json.loads(json_str)
|
|
105
|
+
|
|
106
|
+
# load binary buffer
|
|
107
|
+
if offset < len(self._bin_content):
|
|
108
|
+
type_, _length, bytes_, offset = self._load_chunk(offset)
|
|
109
|
+
if type_ == b"BIN\0":
|
|
110
|
+
self._glb_buffer = bytes_
|
|
111
|
+
|
|
112
|
+
def _load_chunk(self, offset):
|
|
113
|
+
chunk_header = self._unpack_content("<I4s", offset)
|
|
114
|
+
length = chunk_header[0]
|
|
115
|
+
type_ = chunk_header[1]
|
|
116
|
+
data = self._bin_content[offset + 8 : offset + 8 + length] # noqa E203
|
|
117
|
+
|
|
118
|
+
return type_, length, data, offset + 8 + length
|
|
119
|
+
|
|
120
|
+
def _unpack_content(self, fmt, offset=0):
|
|
121
|
+
try:
|
|
122
|
+
chunk = struct.unpack_from(fmt, self._bin_content, offset)
|
|
123
|
+
except TypeError:
|
|
124
|
+
# for Python 2.7 compatibility
|
|
125
|
+
chunk = struct.unpack_from(fmt, self._bin_content.tobytes(), offset)
|
|
126
|
+
return chunk
|
|
127
|
+
|
|
128
|
+
def _check_version(self):
|
|
129
|
+
version = self.json["asset"]["version"]
|
|
130
|
+
if version != "2.0":
|
|
131
|
+
raise Exception("Invalid glTF version. Version 2.0 expected.")
|
|
132
|
+
|
|
133
|
+
def _get_attr_data(self, obj, attr):
|
|
134
|
+
if attr not in obj:
|
|
135
|
+
return None
|
|
136
|
+
buffer_view_index = obj[attr]
|
|
137
|
+
buffer_view = self.json["bufferViews"][buffer_view_index]
|
|
138
|
+
buffer = self._get_buffer(buffer_view["buffer"])
|
|
139
|
+
offset = buffer_view.get("byteOffset", 0)
|
|
140
|
+
length = buffer_view["byteLength"]
|
|
141
|
+
return buffer[offset : offset + length].tobytes() # noqa E203
|
|
142
|
+
|
|
143
|
+
def _access_data(self, accessor):
|
|
144
|
+
count = accessor["count"]
|
|
145
|
+
component_type = accessor["componentType"]
|
|
146
|
+
type_ = accessor["type"]
|
|
147
|
+
accessor_offset = accessor.get("byteOffset", 0)
|
|
148
|
+
num_components = NUM_COMPONENTS_BY_TYPE_ENUM[type_]
|
|
149
|
+
|
|
150
|
+
# This situation indicates use of an extension.
|
|
151
|
+
if "sparse" not in accessor and "bufferView" not in accessor:
|
|
152
|
+
return None
|
|
153
|
+
|
|
154
|
+
if "bufferView" in accessor:
|
|
155
|
+
buffer_view_index = accessor["bufferView"]
|
|
156
|
+
data = self._read_from_buffer_view(
|
|
157
|
+
buffer_view_index,
|
|
158
|
+
count,
|
|
159
|
+
component_type,
|
|
160
|
+
accessor_offset,
|
|
161
|
+
num_components,
|
|
162
|
+
)
|
|
163
|
+
else:
|
|
164
|
+
data = self.get_generic_data(num_components, count)
|
|
165
|
+
|
|
166
|
+
if "sparse" in accessor:
|
|
167
|
+
sparse_data = accessor["sparse"]
|
|
168
|
+
sparse_count = sparse_data["count"]
|
|
169
|
+
|
|
170
|
+
sparse_indices_data = sparse_data["indices"]
|
|
171
|
+
sparse_indices_buffer_view_index = sparse_indices_data["bufferView"]
|
|
172
|
+
sparse_indices_component_type = sparse_indices_data["componentType"]
|
|
173
|
+
sparse_indices = self._read_from_buffer_view(
|
|
174
|
+
sparse_indices_buffer_view_index,
|
|
175
|
+
sparse_count,
|
|
176
|
+
sparse_indices_component_type,
|
|
177
|
+
accessor_offset,
|
|
178
|
+
NUM_COMPONENTS_BY_TYPE_ENUM["SCALAR"],
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
sparse_values_data = sparse_data["values"]
|
|
182
|
+
sparse_values_buffer_view_index = sparse_values_data["bufferView"]
|
|
183
|
+
sparse_values = self._read_from_buffer_view(
|
|
184
|
+
sparse_values_buffer_view_index,
|
|
185
|
+
sparse_count,
|
|
186
|
+
component_type,
|
|
187
|
+
accessor_offset,
|
|
188
|
+
num_components,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
for index, data_index in enumerate(sparse_indices):
|
|
192
|
+
data[data_index] = sparse_values[index]
|
|
193
|
+
|
|
194
|
+
if accessor.get("normalized", False):
|
|
195
|
+
for index, tuple_ in enumerate(data):
|
|
196
|
+
new_tuple = ()
|
|
197
|
+
for i in tuple_:
|
|
198
|
+
if component_type == COMPONENT_TYPE_BYTE:
|
|
199
|
+
new_tuple += (max(float(i / 127.0), -1.0),)
|
|
200
|
+
elif component_type == COMPONENT_TYPE_UNSIGNED_BYTE:
|
|
201
|
+
new_tuple += (float(i / 255.0),)
|
|
202
|
+
elif component_type == COMPONENT_TYPE_SHORT:
|
|
203
|
+
new_tuple += (max(float(i / 32767.0), -1.0),)
|
|
204
|
+
elif component_type == COMPONENT_TYPE_UNSIGNED_SHORT:
|
|
205
|
+
new_tuple += (i / 65535.0,)
|
|
206
|
+
else:
|
|
207
|
+
new_tuple += (float(i),)
|
|
208
|
+
data[index] = new_tuple
|
|
209
|
+
|
|
210
|
+
return data
|
|
211
|
+
|
|
212
|
+
def _read_from_buffer_view(self, buffer_view_index, count, component_type, accessor_offset, num_components):
|
|
213
|
+
buffer_view = self.json["bufferViews"][buffer_view_index]
|
|
214
|
+
|
|
215
|
+
buffer_view_offset = buffer_view.get("byteOffset", 0)
|
|
216
|
+
offset = accessor_offset + buffer_view_offset
|
|
217
|
+
|
|
218
|
+
format_char = COMPONENT_TYPE_ENUM[component_type]
|
|
219
|
+
format_ = "<" + format_char * num_components
|
|
220
|
+
|
|
221
|
+
expected_length = struct.calcsize(format_)
|
|
222
|
+
|
|
223
|
+
component_size = struct.calcsize("<" + format_char)
|
|
224
|
+
if component_type == "MAT2" and component_size == 1:
|
|
225
|
+
format_ = "<FFxxFF".replace("F", format_char)
|
|
226
|
+
expected_length = 8
|
|
227
|
+
elif component_type == "MAT3" and component_size == 1:
|
|
228
|
+
format_ = "<FFFxFFFxFFF".replace("F", format_char)
|
|
229
|
+
expected_length = 12
|
|
230
|
+
elif component_type == "MAT3" and component_size == 2:
|
|
231
|
+
format_ = "<FFFxxFFFxxFFF".replace("F", format_char)
|
|
232
|
+
expected_length = 24
|
|
233
|
+
|
|
234
|
+
byte_stride = buffer_view.get("byteStride", expected_length)
|
|
235
|
+
|
|
236
|
+
unpack_from = struct.Struct(format_).unpack_from
|
|
237
|
+
|
|
238
|
+
buffer_index = buffer_view["buffer"]
|
|
239
|
+
buffer = self._get_buffer(buffer_index)
|
|
240
|
+
|
|
241
|
+
data = [unpack_from(buffer[i : i + byte_stride].tobytes()) for i in range(offset, offset + count * byte_stride, byte_stride)] # noqa E203
|
|
242
|
+
|
|
243
|
+
if num_components == 1:
|
|
244
|
+
data = [item[0] for item in data] # unwrap scalars from tuple
|
|
245
|
+
|
|
246
|
+
return data
|
|
247
|
+
|
|
248
|
+
def _get_buffer(self, buffer_index):
|
|
249
|
+
if buffer_index in self._buffers:
|
|
250
|
+
return self._buffers[buffer_index]
|
|
251
|
+
|
|
252
|
+
uri = self.json["buffers"][buffer_index].get("uri", None)
|
|
253
|
+
|
|
254
|
+
if not uri:
|
|
255
|
+
buffer = self._glb_buffer
|
|
256
|
+
elif self.is_data_uri(uri):
|
|
257
|
+
string = self.get_data_uri_data(uri)
|
|
258
|
+
buffer = self._get_memoryview(base64.b64decode(string))
|
|
259
|
+
else:
|
|
260
|
+
filepath = self.get_filepath(uri)
|
|
261
|
+
with open(filepath, "rb") as f:
|
|
262
|
+
buffer = self._get_memoryview(f.read())
|
|
263
|
+
|
|
264
|
+
self._buffers[buffer_index] = buffer
|
|
265
|
+
|
|
266
|
+
return buffer
|
|
267
|
+
|
|
268
|
+
def _release_buffer(self, buffer):
|
|
269
|
+
try:
|
|
270
|
+
buffer.release()
|
|
271
|
+
except AttributeError:
|
|
272
|
+
# AttributeError indicates using Python <3.2
|
|
273
|
+
pass
|
|
274
|
+
|
|
275
|
+
def _release_buffers(self):
|
|
276
|
+
self._release_buffer(self._glb_buffer)
|
|
277
|
+
self._glb_buffer = None
|
|
278
|
+
for i in range(len(self._buffers)):
|
|
279
|
+
self._release_buffer(self._buffers[i])
|
|
280
|
+
self._buffers = {}
|
|
281
|
+
|
|
282
|
+
def _get_memoryview(self, content):
|
|
283
|
+
try:
|
|
284
|
+
mv = memoryview(content)
|
|
285
|
+
except TypeError:
|
|
286
|
+
# Exception occurs when using IronPython 2.7.8.
|
|
287
|
+
# See https://github.com/IronLanguages/ironpython2/issues/374#issuecomment-390658569
|
|
288
|
+
mv = memoryview(bytearray(content))
|
|
289
|
+
return mv
|
|
290
|
+
|
|
291
|
+
def get_filepath(self, uri):
|
|
292
|
+
dir_path = os.path.dirname(self.filepath)
|
|
293
|
+
return os.path.join(dir_path, uri)
|
|
294
|
+
|
|
295
|
+
def get_mime_type(self, string):
|
|
296
|
+
if string is None or not self.is_data_uri(string):
|
|
297
|
+
return None
|
|
298
|
+
pattern = r"data:([\w/]+)(?<![;,])"
|
|
299
|
+
result = re.search(pattern, string)
|
|
300
|
+
return result.group(1)
|
|
301
|
+
|
|
302
|
+
def get_generic_data(self, num_components, count):
|
|
303
|
+
return [(0,) * num_components for _ in range(count)]
|
|
304
|
+
|
|
305
|
+
def is_data_uri(self, uri):
|
|
306
|
+
return uri.startswith("data:")
|
|
307
|
+
|
|
308
|
+
def get_data_uri_data(self, uri):
|
|
309
|
+
split_uri = uri.split(",")
|
|
310
|
+
return split_uri[-1]
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from compas.files.gltf.gltf_children import GLTFChildren
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class GLTFScene(object):
|
|
9
|
+
"""Object representing the COMPAS consumable part of a glTF scene.
|
|
10
|
+
|
|
11
|
+
Attributes
|
|
12
|
+
----------
|
|
13
|
+
name : str
|
|
14
|
+
Name of the scene.
|
|
15
|
+
children : GLTFChildren
|
|
16
|
+
Validated list of keys referencing :attr:`compas.files.GLTFScene.context.nodes`.
|
|
17
|
+
extras : object
|
|
18
|
+
extensions : object
|
|
19
|
+
context : GLTFContent
|
|
20
|
+
GLTF context in which the scene exists.
|
|
21
|
+
key : int
|
|
22
|
+
Key of the scene within :attr:`compas.files.GLTFContent.scenes`.
|
|
23
|
+
nodes : dict
|
|
24
|
+
Dictionary of nodes in the given scene, without a specified root.
|
|
25
|
+
positions_and_edges : tuple
|
|
26
|
+
Tuple containing a dictionary of positions and a list of tuples representing edges.
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, context, children=None, name=None, extras=None, extensions=None):
|
|
31
|
+
self.name = name
|
|
32
|
+
self._children = GLTFChildren(context, children or [])
|
|
33
|
+
self.extras = extras
|
|
34
|
+
self.extensions = extensions
|
|
35
|
+
|
|
36
|
+
self._key = None
|
|
37
|
+
self.context = context
|
|
38
|
+
self._set_key()
|
|
39
|
+
|
|
40
|
+
def _set_key(self):
|
|
41
|
+
key = len(self.context.scenes)
|
|
42
|
+
while key in self.context.scenes:
|
|
43
|
+
key += 1
|
|
44
|
+
self.context.scenes[key] = self
|
|
45
|
+
self._key = key
|
|
46
|
+
|
|
47
|
+
@property
|
|
48
|
+
def key(self):
|
|
49
|
+
return self._key
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def children(self):
|
|
53
|
+
return self._children
|
|
54
|
+
|
|
55
|
+
@children.setter
|
|
56
|
+
def children(self, value):
|
|
57
|
+
self._children = GLTFChildren(self.context, value or [])
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def nodes(self):
|
|
61
|
+
return self.context.get_nodes_from_scene(self)
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def positions_and_edges(self):
|
|
65
|
+
return self.context.get_scene_positions_and_edges(self)
|
|
66
|
+
|
|
67
|
+
def add_child(self, node_name=None, node_extras=None):
|
|
68
|
+
"""Creates a :class:`compas.files.GLTFNode` and adds this node to the children of `scene`.
|
|
69
|
+
|
|
70
|
+
Parameters
|
|
71
|
+
----------
|
|
72
|
+
node_name : str
|
|
73
|
+
node_extras : object
|
|
74
|
+
|
|
75
|
+
Returns
|
|
76
|
+
-------
|
|
77
|
+
:class:`compas.fikes.GLTFNode`
|
|
78
|
+
"""
|
|
79
|
+
return self.context.add_node_to_scene(self, node_name, node_extras)
|
|
80
|
+
|
|
81
|
+
def to_data(self, node_index_by_key):
|
|
82
|
+
"""Returns a JSONable dictionary object in accordance with glTF specifications.
|
|
83
|
+
|
|
84
|
+
Parameters
|
|
85
|
+
----------
|
|
86
|
+
node_index_by_key : dict
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
dict
|
|
91
|
+
"""
|
|
92
|
+
scene_dict = {}
|
|
93
|
+
if self.children:
|
|
94
|
+
scene_dict["nodes"] = [node_index_by_key[key] for key in self.children]
|
|
95
|
+
if self.name:
|
|
96
|
+
scene_dict["name"] = self.name
|
|
97
|
+
if self.extras:
|
|
98
|
+
scene_dict["extras"] = self.extras
|
|
99
|
+
if self.extensions:
|
|
100
|
+
scene_dict["extensions"] = self.extensions
|
|
101
|
+
return scene_dict
|
|
102
|
+
|
|
103
|
+
@classmethod
|
|
104
|
+
def from_data(cls, scene, context):
|
|
105
|
+
"""Creates a :class:`compas.files.GLTFScene` from a glTF scene dictionary
|
|
106
|
+
and inserts it in the provided context.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
scene : dict
|
|
111
|
+
context : :class:`compas.files.GLTFContent`
|
|
112
|
+
|
|
113
|
+
Returns
|
|
114
|
+
-------
|
|
115
|
+
:class:`compas.files.GLTFScene`
|
|
116
|
+
"""
|
|
117
|
+
if scene is None:
|
|
118
|
+
return None
|
|
119
|
+
return cls(
|
|
120
|
+
context=context,
|
|
121
|
+
children=scene.get("nodes"),
|
|
122
|
+
name=scene.get("name"),
|
|
123
|
+
extras=scene.get("extras"),
|
|
124
|
+
extensions=scene.get("extensions"),
|
|
125
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
import itertools
|
|
6
|
+
import math
|
|
7
|
+
|
|
8
|
+
from compas.files.gltf.constants import MODE_BY_VERTEX_COUNT
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_matrix_from_col_major_list(matrix_as_list):
|
|
12
|
+
return [[matrix_as_list[i + j * 4] for j in range(4)] for i in range(4)]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def matrix_to_col_major_order(matrix):
|
|
16
|
+
return [matrix[i][j] for j in range(4) for i in range(4)]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_morph_function(weights):
|
|
20
|
+
"""Returns a function which computes for a fixed list w of scalar weights the linear combination
|
|
21
|
+
vertex + sum_i(w[i] * targets[i])
|
|
22
|
+
where vertex and targets[i] are vectors."""
|
|
23
|
+
|
|
24
|
+
def apply_weight(weight, target_coordinate):
|
|
25
|
+
return weight * target_coordinate
|
|
26
|
+
|
|
27
|
+
def weighted_sum(vertex_coordinate, *targets_coordinate):
|
|
28
|
+
return vertex_coordinate + math.fsum(map(apply_weight, weights, targets_coordinate))
|
|
29
|
+
|
|
30
|
+
def apply_morph_target(vertex, *targets):
|
|
31
|
+
return tuple(map(weighted_sum, vertex, *targets)) + ((vertex[-1],) if len(vertex) == 4 else ())
|
|
32
|
+
|
|
33
|
+
return apply_morph_target
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def get_weighted_mesh_vertices(mesh, weights):
|
|
37
|
+
"""A mesh may be deformed by several morph targets, with the displacement defined by each target
|
|
38
|
+
being modified by a certain ``weight``. A common use case for such targets and weights would
|
|
39
|
+
be interpolating between two geometries in an animation. This returns the vertices of the augmented
|
|
40
|
+
mesh.
|
|
41
|
+
"""
|
|
42
|
+
vertices = []
|
|
43
|
+
for primitive_data in mesh.primitive_data_list:
|
|
44
|
+
position_target_data = [target["POSITION"] for target in primitive_data.targets]
|
|
45
|
+
apply_morph_targets = get_morph_function(weights)
|
|
46
|
+
vertices += list(map(apply_morph_targets, primitive_data.attributes["POSITION"], *position_target_data))
|
|
47
|
+
return vertices
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_unweighted_primitive_vertices(primitive_data_list):
|
|
51
|
+
"""This returns the vertices within a primitive without any weighted morph targets applied."""
|
|
52
|
+
return list(itertools.chain(*[primitive.attributes["POSITION"] for primitive in primitive_data_list]))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_mode(faces):
|
|
56
|
+
vertex_count = len(faces[0])
|
|
57
|
+
if vertex_count in MODE_BY_VERTEX_COUNT:
|
|
58
|
+
return MODE_BY_VERTEX_COUNT[vertex_count]
|
|
59
|
+
raise Exception("Meshes must be composed of triangles, lines or points.")
|