Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default class SegmentMeshController {
vertices: Float32Array,
segmentId: number,
layerName: string,
opacity: number,
additionalCoordinates?: AdditionalCoordinate[] | undefined | null,
): Promise<void> {
// Currently, this function is only used by ad hoc meshing.
Expand All @@ -129,6 +130,7 @@ export default class SegmentMeshController {
NO_LOD_MESH_INDEX,
layerName,
additionalCoordinates,
opacity,
false,
);
}
Expand All @@ -137,6 +139,7 @@ export default class SegmentMeshController {
segmentId: number,
layerName: string,
geometry: BufferGeometryWithInfo,
opacity: number,
isMerged: boolean,
): MeshSceneNode {
const color = this.getColorObjectForSegment(segmentId, layerName);
Expand Down Expand Up @@ -169,7 +172,7 @@ export default class SegmentMeshController {
tweenAnimation
.to(
{
opacity: 1,
opacity,
},
100,
)
Expand All @@ -189,6 +192,7 @@ export default class SegmentMeshController {
lod: number,
layerName: string,
additionalCoordinates: AdditionalCoordinate[] | null | undefined,
opacity: number,
isMerged: boolean,
): void {
const additionalCoordinatesString = getAdditionalCoordinatesAsString(additionalCoordinates);
Expand Down Expand Up @@ -232,7 +236,7 @@ export default class SegmentMeshController {
];
targetGroup.scale.copy(new THREE.Vector3(...adaptedScale));
}
const meshChunk = this.constructMesh(segmentId, layerName, geometry, isMerged);
const meshChunk = this.constructMesh(segmentId, layerName, geometry, opacity, isMerged);

const group = new THREE.Group() as SceneGroupForMeshes;
group.add(meshChunk);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
} from "types/api_types";
import type { AdditionalCoordinate } from "types/api_types";
import type { Vector3 } from "viewer/constants";
import Constants from "viewer/constants";
import type {
Annotation,
MappingType,
Expand Down Expand Up @@ -333,6 +334,7 @@ export const addAdHocMeshAction = (
seedAdditionalCoordinates: AdditionalCoordinate[] | undefined | null,
mappingName: string | null | undefined,
mappingType: MappingType | null | undefined,
opacity: number = Constants.DEFAULT_MESH_OPACITY,
) =>
({
type: "ADD_AD_HOC_MESH",
Expand All @@ -342,6 +344,7 @@ export const addAdHocMeshAction = (
seedAdditionalCoordinates,
mappingName,
mappingType,
opacity,
}) as const;

export const addPrecomputedMeshAction = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type AdHocMeshInfo = {
mappingType: MappingType | null | undefined;
useDataStore?: boolean | null | undefined;
preferredQuality?: number | null | undefined;
opacity?: number | null | undefined;
};
export type LoadAdHocMeshAction = ReturnType<typeof loadAdHocMeshAction>;
export type LoadPrecomputedMeshAction = ReturnType<typeof loadPrecomputedMeshAction>;
Expand Down Expand Up @@ -34,6 +35,7 @@ export const loadPrecomputedMeshAction = (
seedPosition: Vector3,
seedAdditionalCoordinates: AdditionalCoordinate[] | undefined | null,
meshFileName: string,
opacity?: number,
layerName?: string | undefined,
) =>
({
Expand All @@ -42,5 +44,6 @@ export const loadPrecomputedMeshAction = (
seedPosition,
seedAdditionalCoordinates,
meshFileName,
opacity,
layerName,
}) as const;
16 changes: 15 additions & 1 deletion frontend/javascripts/viewer/model/reducers/annotation_reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ function AnnotationReducer(state: WebknossosState, action: Action): WebknossosSt
additionalCoordinates,
layerName,
);
console.log("REMOVE_MESH", maybeMeshes, state.localSegmentationData[layerName]);
if (maybeMeshes == null || maybeMeshes[segmentId] == null) {
// No meshes exist for the segment id. No need to do anything.
return state;
Expand All @@ -353,6 +354,7 @@ function AnnotationReducer(state: WebknossosState, action: Action): WebknossosSt
seedAdditionalCoordinates,
mappingName,
mappingType,
opacity,
} = action;
const meshInfo: MeshInformation = {
segmentId: segmentId,
Expand All @@ -361,7 +363,7 @@ function AnnotationReducer(state: WebknossosState, action: Action): WebknossosSt
isLoading: false,
isVisible: true,
isPrecomputed: false,
opacity: Constants.DEFAULT_MESH_OPACITY,
opacity,
mappingName,
mappingType,
};
Expand Down Expand Up @@ -454,6 +456,12 @@ function AnnotationReducer(state: WebknossosState, action: Action): WebknossosSt
},
},
});
console.log(
"STARTED_LOADING_MESH",
layerName,
segmentId,
state.localSegmentationData[layerName],
); //TODO_c
return updatedKey;
}

Expand All @@ -477,6 +485,12 @@ function AnnotationReducer(state: WebknossosState, action: Action): WebknossosSt
},
},
});
console.log(
"FINISHED_LOADING_MESH",
layerName,
segmentId,
state.localSegmentationData[layerName],
); //TODO_c
return updatedKey;
}

Expand Down
37 changes: 33 additions & 4 deletions frontend/javascripts/viewer/model/sagas/mesh_saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type { APIDataset, APIMeshFileInfo, APISegmentationLayer } from "types/ap
import type { AdditionalCoordinate } from "types/api_types";
import { WkDevFlags } from "viewer/api/wk_dev";
import type { Vector3, Vector4 } from "viewer/constants";
import { MappingStatusEnum } from "viewer/constants";
import Constants, { MappingStatusEnum } from "viewer/constants";
import CustomLOD from "viewer/controller/custom_lod";
import {
type BufferGeometryWithInfo,
Expand Down Expand Up @@ -343,7 +343,7 @@ function* loadFullAdHocMesh(
removeExistingMesh: boolean,
): Saga<void> {
let isInitialRequest = true;
const { mappingName, mappingType } = meshExtraInfo;
const { mappingName, mappingType, opacity } = meshExtraInfo;
const clippedPosition = clipPositionToCubeBoundary(position, zoomStep, magInfo);
yield* put(
addAdHocMeshAction(
Expand All @@ -353,6 +353,7 @@ function* loadFullAdHocMesh(
additionalCoordinates,
mappingName,
mappingType,
opacity || Constants.DEFAULT_MESH_OPACITY,
),
);
yield* put(startedLoadingMeshAction(layer.name, segmentId));
Expand Down Expand Up @@ -527,6 +528,8 @@ function* maybeLoadMeshChunk(
segmentMeshController.removeMeshById(segmentId, layer.name);
}

const opacity = meshExtraInfo.opacity || Constants.DEFAULT_MESH_OPACITY;

// We await addMeshFromVerticesAsync here, because the mesh saga will remove
// an ad-hoc loaded mesh immediately if it was "empty". Since the check is
// done by looking at the scene, we await the population of the scene.
Expand All @@ -538,6 +541,7 @@ function* maybeLoadMeshChunk(
vertices,
segmentId,
layer.name,
opacity,
additionalCoordinates,
);
return neighbors.map((neighbor) =>
Expand Down Expand Up @@ -621,6 +625,7 @@ function* refreshMesh(action: RefreshMeshAction): Saga<void> {
meshInfo.seedPosition,
meshInfo.seedAdditionalCoordinates,
meshInfo.meshFileName,
meshInfo.opacity,
layerName,
),
);
Expand All @@ -630,7 +635,14 @@ function* refreshMesh(action: RefreshMeshAction): Saga<void> {
if (threeDMap == null) {
return;
}
yield* call(_refreshMeshWithMap, segmentId, threeDMap, layerName, additionalCoordinates);
yield* call(
_refreshMeshWithMap,
segmentId,
threeDMap,
layerName,
additionalCoordinates,
meshInfo.opacity,
);
}
}

Expand All @@ -639,6 +651,7 @@ function* _refreshMeshWithMap(
threeDMap: ThreeDMap<boolean>,
layerName: string,
additionalCoordinates: AdditionalCoordinate[] | null,
opacity: number = Constants.DEFAULT_MESH_OPACITY,
): Saga<void> {
const meshInfo = yield* select((state) =>
getMeshInfoForSegment(state, additionalCoordinates, layerName, segmentId),
Expand All @@ -665,6 +678,10 @@ function* _refreshMeshWithMap(
yield* call(removeMesh, removeMeshAction(layerName, segmentId), false);
// The mesh should only be removed once after re-fetching the mesh first position.
let shouldBeRemoved = true;
const meshInfo2 = yield* select((state) =>
getMeshInfoForSegment(state, additionalCoordinates, layerName, segmentId),
);
console.log(meshInfo2);

for (const [, position] of meshPositions) {
// Reload the mesh at the given position if it isn't already loaded there.
Expand All @@ -679,6 +696,7 @@ function* _refreshMeshWithMap(
{
mappingName,
mappingType,
opacity,
},
);
shouldBeRemoved = false;
Expand Down Expand Up @@ -745,7 +763,8 @@ function* maybeFetchMeshFiles(action: MaybeFetchMeshFilesAction): Saga<void> {
}

function* loadPrecomputedMesh(action: LoadPrecomputedMeshAction) {
const { segmentId, seedPosition, seedAdditionalCoordinates, meshFileName, layerName } = action;
const { segmentId, seedPosition, seedAdditionalCoordinates, meshFileName, layerName, opacity } =
action;
const layer = yield* select((state) =>
layerName != null
? getSegmentationLayerByName(state.dataset, layerName)
Expand All @@ -768,6 +787,7 @@ function* loadPrecomputedMesh(action: LoadPrecomputedMeshAction) {
seedAdditionalCoordinates,
meshFileName,
layer,
opacity || Constants.DEFAULT_MESH_OPACITY,
),
cancel: take(
((otherAction: Action) =>
Expand All @@ -786,6 +806,7 @@ function* loadPrecomputedMeshForSegmentId(
seedAdditionalCoordinates: AdditionalCoordinate[] | undefined | null,
meshFileName: string,
segmentationLayer: APISegmentationLayer,
opacity: number,
): Saga<void> {
const layerName = segmentationLayer.name;
const mappingName = yield* call(getMappingName, segmentationLayer);
Expand All @@ -799,6 +820,9 @@ function* loadPrecomputedMeshForSegmentId(
mappingName,
),
);
if (opacity != null) {
//yield* put(updateMeshOpacityAction(layerName, segmentId, opacity));
}
yield* put(startedLoadingMeshAction(layerName, segmentId));
const dataset = yield* select((state) => state.dataset);
const additionalCoordinates = yield* select((state) => state.flycam.additionalCoordinates);
Expand Down Expand Up @@ -864,6 +888,7 @@ function* loadPrecomputedMeshForSegmentId(
(lod: number) => extractScaleFromMatrix(lods[lod].transform),
chunkScale,
additionalCoordinates,
opacity,
);
}

Expand Down Expand Up @@ -972,6 +997,7 @@ function* loadPrecomputedMeshesInChunksForLod(
getGlobalScale: (lod: number) => Vector3 | null,
chunkScale: Vector3 | null,
additionalCoordinates: AdditionalCoordinate[] | null,
opacity: number,
) {
const { segmentMeshController } = getSceneController();
const loader = getDracoLoader();
Expand Down Expand Up @@ -1047,6 +1073,7 @@ function* loadPrecomputedMeshesInChunksForLod(
lod,
layerName,
additionalCoordinates,
opacity,
false,
);

Expand Down Expand Up @@ -1114,6 +1141,7 @@ function* loadPrecomputedMeshesInChunksForLod(
lod,
layerName,
additionalCoordinates,
opacity,
true,
);
}
Expand Down Expand Up @@ -1303,6 +1331,7 @@ function* handleSegmentColorChange(action: UpdateSegmentAction): Saga<void> {
}

function* handleMeshOpacityChange(action: UpdateMeshOpacityAction): Saga<void> {
console.log("handleMeshOpacityChange", action);
const { segmentMeshController } = yield* call(getSceneController);
segmentMeshController.setMeshOpacity(action.id, action.layerName, action.opacity);
}
Expand Down
Loading