traverse for colors

This commit is contained in:
KatKatKateryna
2024-09-04 11:32:11 +01:00
parent 93e0cd5792
commit eb381bdd2f
2 changed files with 54 additions and 18 deletions
@@ -168,9 +168,11 @@ def get_single_display_object(displayValForColor: List) -> "Base":
displayValForColor = item
mesh = Mesh.create(faces= faces, vertices=verts, colors=colors)
for prop in displayValForColor[0].get_member_names():
if prop not in ["colors", "vertices", "faces"]:
mesh[prop] = getattr(displayValForColor[0], prop)
if len(displayValForColor)>0:
for prop in displayValForColor[0].get_member_names():
if prop not in ["colors", "vertices", "faces"]:
mesh[prop] = getattr(displayValForColor[0], prop)
displayValForColor = mesh
return displayValForColor
@@ -258,22 +260,42 @@ def set_default_color(context_list: List["TraversalContext"]) -> None:
DEFAULT_COLOR = (255 << 24) + (10 << 16) + (132 << 8) + 255
break
def assign_color(self: "SpeckleProvider", obj_display, props) -> None:
def getAllParents(tc: "TraversalContext"):
all_tc = [tc]
while True:
try:
parent = tc.parent
if parent:
all_tc.append(parent)
tc = parent
else:
break
except:
break
return all_tc
def assign_color(self: "SpeckleProvider", obj_display_tc: "TraversalContext", props: Dict) -> None:
"""Get and assign color to feature displayProperties."""
from specklepy.objects.geometry import Base, Mesh, Brep
try:
color = self.material_color_proxies[obj_display.applicationId]
props['color'] = color
return
except:
pass
from specklepy.objects.geometry import Mesh, Brep
for tc in getAllParents(obj_display_tc):
try:
color = self.material_color_proxies[tc.current.applicationId]
props['color'] = color
return
except:
pass
# initialize Speckle Blue color
color = DEFAULT_COLOR
opacity = None
obj_display = obj_display_tc.current
try:
# prioritize renderMaterials for Meshes & Brep
if isinstance(obj_display, Mesh) or isinstance(obj_display, Brep):
@@ -336,12 +358,12 @@ def get_r_g_b(rgb: int) -> Tuple[int, int, int]:
a = 255
return a, r, g, b
def assign_display_properties(self: "SpeckleProvider", feature: Dict, f_base: "Base", obj_display: "Base") -> None:
def assign_display_properties(self: "SpeckleProvider", feature: Dict, f_base: "Base", obj_display_tc: "TraversalContext") -> None:
"""Assign displayProperties to the feature."""
from specklepy.objects.geometry import Mesh, Brep
assign_color(self, obj_display, feature["displayProperties"])
assign_color(self, obj_display_tc, feature["displayProperties"])
feature["properties"]["color"] = feature["displayProperties"]["color"]
# other properties for rendering
@@ -10,6 +10,9 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
from pygeoapi.provider.speckle_utils.converter_utils import assign_geometry
from pygeoapi.provider.speckle_utils.display_utils import find_display_obj, assign_display_properties, find_list_of_display_obj
from specklepy.objects.graph_traversal.traversal import TraversalContext
from specklepy.objects.other import Collection
print(f"Creating features..")
time1 = datetime.now()
@@ -19,6 +22,9 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
if self.requested_data_type != "projectcomments":
for item in context_list:
if item.current.speckle_type.endswith("Collection") or item.current.speckle_type.endswith("Layer") or item.current.speckle_type.endswith("Proxy"):
continue
if feature_count >= self.limit:
self.limit_message = f" (feature count limited to {self.limit})"
break
@@ -28,6 +34,10 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
f_fid = feature_count + 1
# initialize feature
speckle_type = item.current.speckle_type
if ":" in speckle_type:
speckle_type = speckle_type.split(":")[-1]
feature: Dict = {
"type": "Feature",
# "bbox": [-180.0, -90.0, 180.0, 90.0],
@@ -38,7 +48,7 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
"properties": {
"id": f_id,
"FID": f_fid,
"speckle_type": item.current.speckle_type.split(":")[-1],
"speckle_type": speckle_type,
},
}
@@ -67,7 +77,9 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
if prop not in all_props:
all_props.append(prop)
assign_display_properties(self, feature, f_base, obj_get_color)
obj_get_color_tc = TraversalContext(obj_get_color, "", item)
assign_display_properties(self, feature, f_base, obj_get_color_tc)
feature["max_height"] = max([c[2] for c in coords])
data["features"].append(feature)
feature_count += 1
@@ -107,11 +119,13 @@ def initialize_features(self: "SpeckleProvider", all_coords, all_coord_counts, d
all_coords.extend(coords)
all_coord_counts.append(coord_counts)
assign_display_properties(self, feature_new, f_base, obj_get_color)
obj_get_color_tc = TraversalContext(obj_get_color, "", item)
assign_display_properties(self, feature_new, f_base, obj_get_color_tc)
feature_new["max_height"] = max([c[2] for c in coords])
data["features"].append(feature_new)
feature_count +=1
assign_missing_props(data["features"], all_props)
else:
####################### create comment features