@neurodyn/react-room-viewer 0.0.24 → 0.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +134 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -7725,7 +7725,10 @@ async function fetchRoomViewerOwnerObjects(ownerUuid, page, options) {
|
|
|
7725
7725
|
signal: options.signal
|
|
7726
7726
|
});
|
|
7727
7727
|
const { query, config } = getRoomViewerPublicApiQuery(options);
|
|
7728
|
-
const response = await publicApiControllerGetPublicObjects(
|
|
7728
|
+
const response = await publicApiControllerGetPublicObjects({
|
|
7729
|
+
...data,
|
|
7730
|
+
productType: getRoomViewerPublicApiProductType(options)
|
|
7731
|
+
}, query, {
|
|
7729
7732
|
...config,
|
|
7730
7733
|
baseURL: options.baseURL,
|
|
7731
7734
|
headers: await getRoomViewerPublicApiHeaders(options),
|
|
@@ -14875,6 +14878,120 @@ function panelModelQuery(url) {
|
|
|
14875
14878
|
retry: false
|
|
14876
14879
|
};
|
|
14877
14880
|
}
|
|
14881
|
+
function usePanelMaterials(currentObject, enabled) {
|
|
14882
|
+
const { apiKey, baseURL, source, widgetSession } = useRoomViewerResource();
|
|
14883
|
+
const { type } = useRoomViewerMetadata();
|
|
14884
|
+
const kitUuid = currentObject?.kit?.uuid;
|
|
14885
|
+
const ownerUuid = currentObject?.owner?.uuid;
|
|
14886
|
+
const options = {
|
|
14887
|
+
apiKey,
|
|
14888
|
+
baseURL,
|
|
14889
|
+
source,
|
|
14890
|
+
widgetSession,
|
|
14891
|
+
resourceType: type
|
|
14892
|
+
};
|
|
14893
|
+
const { data, hasNextPage, fetchNextPage, isFetching, isFetchNextPageError } = useInfiniteQuery({
|
|
14894
|
+
queryKey: [
|
|
14895
|
+
...roomViewerKitObjectsQueryKey(kitUuid, ownerUuid, options),
|
|
14896
|
+
'panel-materials'
|
|
14897
|
+
],
|
|
14898
|
+
enabled: enabled && Boolean(kitUuid),
|
|
14899
|
+
queryFn: async ({ pageParam, signal })=>{
|
|
14900
|
+
try {
|
|
14901
|
+
return await fetchRoomViewerKitObjects(kitUuid, ownerUuid ?? '', pageParam, {
|
|
14902
|
+
...options,
|
|
14903
|
+
signal
|
|
14904
|
+
});
|
|
14905
|
+
} catch (error) {
|
|
14906
|
+
if (0 === pageParam || signal.aborted) throw error;
|
|
14907
|
+
return {
|
|
14908
|
+
objs: [],
|
|
14909
|
+
pages_count: void 0
|
|
14910
|
+
};
|
|
14911
|
+
}
|
|
14912
|
+
},
|
|
14913
|
+
initialPageParam: 0,
|
|
14914
|
+
getNextPageParam: (lastPage, pages, page)=>{
|
|
14915
|
+
const count = lastPage.pages_count ?? pages[0]?.pages_count;
|
|
14916
|
+
return void 0 !== count ? page + 1 < count ? page + 1 : void 0 : lastPage.objs?.length ? page + 1 : void 0;
|
|
14917
|
+
},
|
|
14918
|
+
retry: false
|
|
14919
|
+
});
|
|
14920
|
+
(0, __rspack_external_react.useEffect)(()=>{
|
|
14921
|
+
if (enabled && hasNextPage && !isFetching && !isFetchNextPageError) fetchNextPage({
|
|
14922
|
+
cancelRefetch: false
|
|
14923
|
+
});
|
|
14924
|
+
}, [
|
|
14925
|
+
data?.pages.length,
|
|
14926
|
+
enabled,
|
|
14927
|
+
fetchNextPage,
|
|
14928
|
+
hasNextPage,
|
|
14929
|
+
isFetching,
|
|
14930
|
+
isFetchNextPageError
|
|
14931
|
+
]);
|
|
14932
|
+
const siblings = (0, __rspack_external_react.useMemo)(()=>{
|
|
14933
|
+
if (!enabled || !kitUuid) return [];
|
|
14934
|
+
const objects = new Map();
|
|
14935
|
+
for (const object of data?.pages.flatMap((page)=>page.objs ?? []) ?? [])if (object.tinuuid && object.tinuuid !== currentObject?.tinuuid) objects.set(object.tinuuid, object);
|
|
14936
|
+
return Array.from(objects.values());
|
|
14937
|
+
}, [
|
|
14938
|
+
currentObject?.tinuuid,
|
|
14939
|
+
data,
|
|
14940
|
+
enabled,
|
|
14941
|
+
kitUuid
|
|
14942
|
+
]);
|
|
14943
|
+
const details = useQueries({
|
|
14944
|
+
queries: siblings.map((object)=>({
|
|
14945
|
+
queryKey: roomViewerObjectQueryKey(object.tinuuid, options),
|
|
14946
|
+
queryFn: ({ signal })=>fetchRoomViewerObject(object.tinuuid, {
|
|
14947
|
+
...options,
|
|
14948
|
+
signal
|
|
14949
|
+
}),
|
|
14950
|
+
enabled,
|
|
14951
|
+
retry: false
|
|
14952
|
+
}))
|
|
14953
|
+
});
|
|
14954
|
+
const [resolvedResourceOrder, setResolvedResourceOrder] = (0, __rspack_external_react.useState)({
|
|
14955
|
+
ids: []
|
|
14956
|
+
});
|
|
14957
|
+
const sameSelection = resolvedResourceOrder.resourceId === currentObject?.tinuuid && resolvedResourceOrder.kitUuid === kitUuid;
|
|
14958
|
+
const previousIds = sameSelection ? resolvedResourceOrder.ids : [];
|
|
14959
|
+
const knownIds = new Set(previousIds);
|
|
14960
|
+
const resolvedMaterials = new Map(siblings.flatMap((object, index)=>{
|
|
14961
|
+
const detail = details[index]?.data;
|
|
14962
|
+
return detail ? [
|
|
14963
|
+
[
|
|
14964
|
+
object.tinuuid,
|
|
14965
|
+
detail.materials ?? []
|
|
14966
|
+
]
|
|
14967
|
+
] : [];
|
|
14968
|
+
}));
|
|
14969
|
+
const newIds = Array.from(resolvedMaterials.keys()).filter((id)=>!knownIds.has(id));
|
|
14970
|
+
const resourceIds = newIds.length ? [
|
|
14971
|
+
...previousIds,
|
|
14972
|
+
...newIds
|
|
14973
|
+
] : previousIds;
|
|
14974
|
+
if (!sameSelection || newIds.length) setResolvedResourceOrder({
|
|
14975
|
+
resourceId: currentObject?.tinuuid,
|
|
14976
|
+
kitUuid,
|
|
14977
|
+
ids: resourceIds
|
|
14978
|
+
});
|
|
14979
|
+
const allMaterials = enabled ? [
|
|
14980
|
+
...currentObject?.materials ?? [],
|
|
14981
|
+
...resourceIds.flatMap((id)=>resolvedMaterials.get(id) ?? [])
|
|
14982
|
+
] : [];
|
|
14983
|
+
const seen = new Set();
|
|
14984
|
+
return allMaterials.flatMap((material, index)=>{
|
|
14985
|
+
if (!material.hid || !material.native?.glbUrl || seen.has(material.hid)) return [];
|
|
14986
|
+
seen.add(material.hid);
|
|
14987
|
+
return [
|
|
14988
|
+
{
|
|
14989
|
+
material,
|
|
14990
|
+
number: index + 1
|
|
14991
|
+
}
|
|
14992
|
+
];
|
|
14993
|
+
});
|
|
14994
|
+
}
|
|
14878
14995
|
function panelCellKey(cell) {
|
|
14879
14996
|
return `${cell.x},${cell.y}`;
|
|
14880
14997
|
}
|
|
@@ -15043,7 +15160,8 @@ function usePanelSession(enabled, introduce) {
|
|
|
15043
15160
|
const firstMaterial = currentObject?.materials?.[0];
|
|
15044
15161
|
const isPhone = useMediaQuery('(max-width: 639px)');
|
|
15045
15162
|
const composition = usePanelComposition(tinuuid, firstMaterial?.hid ?? '', introduce && isPhone);
|
|
15046
|
-
const
|
|
15163
|
+
const entries = usePanelMaterials(currentObject, enabled && viewerDialogOpen);
|
|
15164
|
+
const materials = entries.map((entry)=>entry.material);
|
|
15047
15165
|
const queries = useQueries({
|
|
15048
15166
|
queries: materials.map((material)=>({
|
|
15049
15167
|
...panelModelQuery(material.native.glbUrl),
|
|
@@ -15053,7 +15171,7 @@ function usePanelSession(enabled, introduce) {
|
|
|
15053
15171
|
const base = queries[materials.findIndex((material)=>material.hid === firstMaterial?.hid)]?.data;
|
|
15054
15172
|
const options = materials.map((material, index)=>({
|
|
15055
15173
|
material,
|
|
15056
|
-
number:
|
|
15174
|
+
number: entries[index].number,
|
|
15057
15175
|
model: queries[index]?.data,
|
|
15058
15176
|
loading: queries[index]?.isFetching ?? false,
|
|
15059
15177
|
error: queries[index]?.isError ?? false
|
|
@@ -17892,9 +18010,21 @@ function AR({ className, buttonClassName, buttonLeadingIcon, buttonLabel, button
|
|
|
17892
18010
|
setIsSceneExporting(true);
|
|
17893
18011
|
const clone = sceneResource.clone(true);
|
|
17894
18012
|
clone.position.set(0, 0, 0);
|
|
18013
|
+
clone.quaternion.identity();
|
|
18014
|
+
clone.updateMatrix();
|
|
18015
|
+
clone.updateMatrixWorld(true);
|
|
17895
18016
|
if (isIOS) {
|
|
17896
18017
|
const usdzExporter = new USDZExporter();
|
|
17897
|
-
const usdzBuffer = await usdzExporter.parseAsync(clone
|
|
18018
|
+
const usdzBuffer = await usdzExporter.parseAsync(clone, {
|
|
18019
|
+
ar: {
|
|
18020
|
+
anchoring: {
|
|
18021
|
+
type: 'plane'
|
|
18022
|
+
},
|
|
18023
|
+
planeAnchoring: {
|
|
18024
|
+
alignment: 'vertical'
|
|
18025
|
+
}
|
|
18026
|
+
}
|
|
18027
|
+
});
|
|
17898
18028
|
const usdzFile = new File([
|
|
17899
18029
|
usdzBuffer
|
|
17900
18030
|
], 'scene.usdz', {
|