mirror of
https://github.com/yeicor-3d/yet-another-cad-viewer.git
synced 2025-12-19 22:24:17 +01:00
Add async buffered pubsub, websocket updates endpoint and initial fast hashing of objects
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import concurrent
|
||||
import copyreg
|
||||
import hashlib
|
||||
import io
|
||||
import re
|
||||
from concurrent.futures import ProcessPoolExecutor, Executor
|
||||
from dataclasses import dataclass
|
||||
from typing import Tuple, Callable, Generator
|
||||
@@ -9,7 +12,9 @@ import numpy as np
|
||||
from OCP.BRep import BRep_Tool
|
||||
from OCP.BRepAdaptor import BRepAdaptor_Curve
|
||||
from OCP.GCPnts import GCPnts_TangentialDeflection
|
||||
from OCP.TopExp import TopExp
|
||||
from OCP.TopLoc import TopLoc_Location
|
||||
from OCP.TopTools import TopTools_IndexedMapOfShape
|
||||
from OCP.TopoDS import TopoDS_Face, TopoDS_Edge, TopoDS_Shape, TopoDS_Vertex
|
||||
from build123d import Face, Vector, Shape, Vertex
|
||||
from partcad.wrappers import cq_serialize
|
||||
@@ -188,3 +193,21 @@ def _tessellate_vertex(ocp_vertex: TopoDS_Vertex) -> GLTF2:
|
||||
pbrMetallicRoughness=PbrMetallicRoughness(baseColorFactor=[1.0, 0.5, 0.5, 1.0]),
|
||||
alphaCutoff=None)
|
||||
return create_gltf(vertices, indices, tex_coord, mode, material)
|
||||
|
||||
|
||||
def _hashcode(obj: TopoDS_Shape) -> str:
|
||||
"""Utility to compute the hash code of a shape recursively without the need to tessellate it"""
|
||||
# NOTE: obj.HashCode(MAX_HASH_CODE) is not stable across different runs of the same program
|
||||
# This is best-effort and not guaranteed to be unique
|
||||
data = io.BytesIO()
|
||||
map_of_shapes = TopTools_IndexedMapOfShape()
|
||||
TopExp.MapShapes_s(obj, map_of_shapes)
|
||||
for i in range(1, map_of_shapes.Extent() + 1):
|
||||
sub_shape = map_of_shapes.FindKey(i)
|
||||
sub_data = io.BytesIO()
|
||||
TopoDS_Shape.DumpJson(sub_shape, sub_data)
|
||||
val = sub_data.getvalue()
|
||||
val = re.sub(b'"this": "[^"]*"', b'', val) # Remove memory address
|
||||
data.write(val)
|
||||
to_hash = data.getvalue()
|
||||
return hashlib.md5(to_hash, usedforsecurity=False).hexdigest()
|
||||
|
||||
Reference in New Issue
Block a user