Skip to content

Commit ad389b2

Browse files
Show selection in transparency for non-visible objects (#587)
* Show selection in transparency for non-visible objects * Fix initial upon transparency * Store jcObject in userData * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 7083583 commit ad389b2

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

packages/base/src/3dview/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ export function buildShape(options: {
190190
const meshGroup = new THREE.Group();
191191
meshGroup.name = `${objName}-group`;
192192
meshGroup.visible = visible;
193+
meshGroup.userData = {
194+
jcObject
195+
};
193196

194197
// We only build the stencil logic for solid meshes
195198
if (isSolid) {

packages/base/src/3dview/mainview.tsx

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ export class MainView extends React.Component<IProps, IStates> {
781781

782782
if (output) {
783783
const { meshGroup, mainMesh, edgesMeshes } = output;
784-
if (meshGroup.visible) {
784+
if (meshGroup.userData.jcObject.visible) {
785785
this._boundingGroup.expandByObject(mainMesh);
786786
}
787787

@@ -804,6 +804,12 @@ export class MainView extends React.Component<IProps, IStates> {
804804
boundingBox.visible = true;
805805
}
806806

807+
if (!meshGroup.userData.jcObject.visible) {
808+
meshGroup.visible = true;
809+
mainMesh.material.opacity = 0.5;
810+
mainMesh.material.transparent = true;
811+
}
812+
807813
this._selectedMeshes.push(mainMesh);
808814
}
809815
edgesMeshes.forEach(el => {
@@ -947,7 +953,6 @@ export class MainView extends React.Component<IProps, IStates> {
947953
const wireframe = new THREE.LineSegments(lineGeo, mat);
948954
mesh.add(wireframe);
949955
mesh.name = name;
950-
mesh.visible = true;
951956
if (this._meshGroup) {
952957
this._meshGroup.add(mesh);
953958
this._boundingGroup?.expandByObject(mesh);
@@ -1104,16 +1109,22 @@ export class MainView extends React.Component<IProps, IStates> {
11041109
selectedMesh.material.color = originalColor;
11051110
}
11061111

1107-
const parentGroup = this._meshGroup?.getObjectByName(
1108-
selectedMesh.name
1109-
)?.parent;
1112+
const parentGroup = this._meshGroup?.getObjectByName(selectedMesh.name)
1113+
?.parent as THREE.Group;
11101114
const boundingBox = parentGroup?.getObjectByName(
11111115
SELECTION_BOUNDING_BOX
11121116
) as THREE.Mesh;
1117+
11131118
if (boundingBox) {
11141119
boundingBox.visible = false;
11151120
}
11161121

1122+
if (!parentGroup.userData.jcObject.visible) {
1123+
parentGroup.visible = false;
1124+
selectedMesh.material.opacity = 1;
1125+
selectedMesh.material.transparent = false;
1126+
}
1127+
11171128
const material = selectedMesh.material as THREE.Material & {
11181129
linewidth?: number;
11191130
};
@@ -1131,18 +1142,19 @@ export class MainView extends React.Component<IProps, IStates> {
11311142
selectionName
11321143
) as BasicMesh;
11331144

1134-
if (!selectedMesh || !selectedMesh.visible) {
1145+
if (!selectedMesh) {
11351146
continue;
11361147
}
11371148

1149+
this._selectedMeshes.push(selectedMesh);
1150+
11381151
if (selectedMesh.name.startsWith('edge')) {
11391152
// Highlight edges using the old method
11401153
if (!selectedMesh.userData.originalColor) {
11411154
selectedMesh.userData.originalColor =
11421155
selectedMesh.material.color.clone();
11431156
}
11441157

1145-
this._selectedMeshes.push(selectedMesh);
11461158
if (selectedMesh?.material?.color) {
11471159
selectedMesh.material.color = BOUNDING_BOX_COLOR;
11481160
}
@@ -1155,11 +1167,15 @@ export class MainView extends React.Component<IProps, IStates> {
11551167
}
11561168
} else {
11571169
// Highlight non-edges using a bounding box
1158-
this._selectedMeshes.push(selectedMesh);
1170+
const parentGroup = this._meshGroup?.getObjectByName(selectedMesh.name)
1171+
?.parent as THREE.Group;
1172+
1173+
if (!parentGroup.userData.jcObject.visible) {
1174+
parentGroup.visible = true;
1175+
selectedMesh.material.opacity = 0.5;
1176+
selectedMesh.material.transparent = true;
1177+
}
11591178

1160-
const parentGroup = this._meshGroup?.getObjectByName(
1161-
selectedMesh.name
1162-
)?.parent;
11631179
const boundingBox = parentGroup?.getObjectByName(
11641180
SELECTION_BOUNDING_BOX
11651181
) as THREE.Mesh;
@@ -1377,6 +1393,7 @@ export class MainView extends React.Component<IProps, IStates> {
13771393
const objColor = obj?.material.color;
13781394

13791395
obj.parent!.visible = isVisible;
1396+
obj.parent!.userData.visible = isVisible;
13801397

13811398
const explodedLineHelper =
13821399
this._explodedViewLinesHelperGroup?.getObjectByName(objName);

0 commit comments

Comments
 (0)