forked from 1b-agent/opencadstudio-upstream
feat(proxy): honour proxy-graphics colour traits
The preview stream sets a current colour (record type 14, an ACI) before its geometry; track it and tag each decoded primitive. The Unknown-entity path groups primitives by colour and draws one wire per colour, resolving a real index (1..=255) to its RGB and letting ByLayer/ByBlock inherit the entity colour. So a custom entity's preview now renders in its own colours (e.g. an ACA door's blue swing) instead of a single flat colour. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
18d116bb33
commit
1d117f514c
2 files changed
+54
-20
No files matched your search
+29
-12
@@ -246,22 +246,39 @@ pub(crate) fn tessellate_entity(
|
||||
if let Some(blob) = e.common().graphic_data.as_ref() {
|
||||
let polys = convert::proxy_graphics::decode(blob);
|
||||
if !polys.is_empty() {
|
||||
// One wire for the whole preview: concatenate the poly-lines
|
||||
// with NaN separators (arcs are already flattened to points).
|
||||
// Group primitives by their preview colour so each colour draws
|
||||
// in its own wire (the poly-lines within share a wire, joined by
|
||||
// NaN separators; arcs are already flattened to points).
|
||||
use std::collections::BTreeMap;
|
||||
let nan = [f64::NAN; 3];
|
||||
let mut pts64: Vec<[f64; 3]> = Vec::new();
|
||||
let mut by_color: BTreeMap<i32, Vec<[f64; 3]>> = BTreeMap::new();
|
||||
for poly in &polys {
|
||||
if !pts64.is_empty() {
|
||||
pts64.push(nan);
|
||||
let buf = by_color.entry(poly.color).or_default();
|
||||
if !buf.is_empty() {
|
||||
buf.push(nan);
|
||||
}
|
||||
pts64.extend_from_slice(&poly.points);
|
||||
buf.extend_from_slice(&poly.points);
|
||||
}
|
||||
let (pts, pts_low) = convert::tessellate::points_to_ds(pts64);
|
||||
let mut w = WireModel::solid(h.value().to_string(), pts, entity_color, sel);
|
||||
w.points_low = pts_low;
|
||||
w.line_weight_px = line_weight_px;
|
||||
w.aci = aci;
|
||||
return vec![w];
|
||||
let mut wires = Vec::with_capacity(by_color.len());
|
||||
for (pcolor, pts64) in by_color {
|
||||
// A real ACI index overrides the entity colour; ByLayer
|
||||
// (256) / ByBlock (0) inherit it.
|
||||
let (col, w_aci) = if (1..=255).contains(&pcolor) {
|
||||
let rgba = convert::tess_util::aci_to_rgba(
|
||||
&acadrust::types::Color::Index(pcolor as u8),
|
||||
);
|
||||
(view::render::adapt_to_bg(rgba, bg_color), pcolor as u8)
|
||||
} else {
|
||||
(entity_color, aci)
|
||||
};
|
||||
let (pts, pts_low) = convert::tessellate::points_to_ds(pts64);
|
||||
let mut w = WireModel::solid(h.value().to_string(), pts, col, sel);
|
||||
w.points_low = pts_low;
|
||||
w.line_weight_px = line_weight_px;
|
||||
w.aci = w_aci;
|
||||
wires.push(w);
|
||||
}
|
||||
return wires;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user