@neurodyn/react-room-viewer 0.0.24 → 0.0.26

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.
Files changed (2) hide show
  1. package/dist/index.js +151 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -7423,6 +7423,19 @@ async function inferenceControllerRunRoomPlanesRaw(data, config = {}) {
7423
7423
  });
7424
7424
  return res.data;
7425
7425
  }
7426
+ async function layoutControllerReadLayoutConfig(headers, config = {}) {
7427
+ const { client: request = node_client_node_client, ...requestConfig } = config;
7428
+ const res = await request({
7429
+ method: "POST",
7430
+ url: "/layout/GetConfig",
7431
+ ...requestConfig,
7432
+ headers: {
7433
+ ...headers,
7434
+ ...requestConfig.headers
7435
+ }
7436
+ });
7437
+ return res.data;
7438
+ }
7426
7439
  async function publicApiControllerActivateWallart(params, config = {}) {
7427
7440
  const { client: request = node_client_node_client, ...requestConfig } = config;
7428
7441
  const res = await request({
@@ -7725,7 +7738,10 @@ async function fetchRoomViewerOwnerObjects(ownerUuid, page, options) {
7725
7738
  signal: options.signal
7726
7739
  });
7727
7740
  const { query, config } = getRoomViewerPublicApiQuery(options);
7728
- const response = await publicApiControllerGetPublicObjects(data, query, {
7741
+ const response = await publicApiControllerGetPublicObjects({
7742
+ ...data,
7743
+ productType: getRoomViewerPublicApiProductType(options)
7744
+ }, query, {
7729
7745
  ...config,
7730
7746
  baseURL: options.baseURL,
7731
7747
  headers: await getRoomViewerPublicApiHeaders(options),
@@ -14875,6 +14891,120 @@ function panelModelQuery(url) {
14875
14891
  retry: false
14876
14892
  };
14877
14893
  }
14894
+ function usePanelMaterials(currentObject, enabled) {
14895
+ const { apiKey, baseURL, source, widgetSession } = useRoomViewerResource();
14896
+ const { type } = useRoomViewerMetadata();
14897
+ const kitUuid = currentObject?.kit?.uuid;
14898
+ const ownerUuid = currentObject?.owner?.uuid;
14899
+ const options = {
14900
+ apiKey,
14901
+ baseURL,
14902
+ source,
14903
+ widgetSession,
14904
+ resourceType: type
14905
+ };
14906
+ const { data, hasNextPage, fetchNextPage, isFetching, isFetchNextPageError } = useInfiniteQuery({
14907
+ queryKey: [
14908
+ ...roomViewerKitObjectsQueryKey(kitUuid, ownerUuid, options),
14909
+ 'panel-materials'
14910
+ ],
14911
+ enabled: enabled && Boolean(kitUuid),
14912
+ queryFn: async ({ pageParam, signal })=>{
14913
+ try {
14914
+ return await fetchRoomViewerKitObjects(kitUuid, ownerUuid ?? '', pageParam, {
14915
+ ...options,
14916
+ signal
14917
+ });
14918
+ } catch (error) {
14919
+ if (0 === pageParam || signal.aborted) throw error;
14920
+ return {
14921
+ objs: [],
14922
+ pages_count: void 0
14923
+ };
14924
+ }
14925
+ },
14926
+ initialPageParam: 0,
14927
+ getNextPageParam: (lastPage, pages, page)=>{
14928
+ const count = lastPage.pages_count ?? pages[0]?.pages_count;
14929
+ return void 0 !== count ? page + 1 < count ? page + 1 : void 0 : lastPage.objs?.length ? page + 1 : void 0;
14930
+ },
14931
+ retry: false
14932
+ });
14933
+ (0, __rspack_external_react.useEffect)(()=>{
14934
+ if (enabled && hasNextPage && !isFetching && !isFetchNextPageError) fetchNextPage({
14935
+ cancelRefetch: false
14936
+ });
14937
+ }, [
14938
+ data?.pages.length,
14939
+ enabled,
14940
+ fetchNextPage,
14941
+ hasNextPage,
14942
+ isFetching,
14943
+ isFetchNextPageError
14944
+ ]);
14945
+ const siblings = (0, __rspack_external_react.useMemo)(()=>{
14946
+ if (!enabled || !kitUuid) return [];
14947
+ const objects = new Map();
14948
+ for (const object of data?.pages.flatMap((page)=>page.objs ?? []) ?? [])if (object.tinuuid && object.tinuuid !== currentObject?.tinuuid) objects.set(object.tinuuid, object);
14949
+ return Array.from(objects.values());
14950
+ }, [
14951
+ currentObject?.tinuuid,
14952
+ data,
14953
+ enabled,
14954
+ kitUuid
14955
+ ]);
14956
+ const details = useQueries({
14957
+ queries: siblings.map((object)=>({
14958
+ queryKey: roomViewerObjectQueryKey(object.tinuuid, options),
14959
+ queryFn: ({ signal })=>fetchRoomViewerObject(object.tinuuid, {
14960
+ ...options,
14961
+ signal
14962
+ }),
14963
+ enabled,
14964
+ retry: false
14965
+ }))
14966
+ });
14967
+ const [resolvedResourceOrder, setResolvedResourceOrder] = (0, __rspack_external_react.useState)({
14968
+ ids: []
14969
+ });
14970
+ const sameSelection = resolvedResourceOrder.resourceId === currentObject?.tinuuid && resolvedResourceOrder.kitUuid === kitUuid;
14971
+ const previousIds = sameSelection ? resolvedResourceOrder.ids : [];
14972
+ const knownIds = new Set(previousIds);
14973
+ const resolvedMaterials = new Map(siblings.flatMap((object, index)=>{
14974
+ const detail = details[index]?.data;
14975
+ return detail ? [
14976
+ [
14977
+ object.tinuuid,
14978
+ detail.materials ?? []
14979
+ ]
14980
+ ] : [];
14981
+ }));
14982
+ const newIds = Array.from(resolvedMaterials.keys()).filter((id)=>!knownIds.has(id));
14983
+ const resourceIds = newIds.length ? [
14984
+ ...previousIds,
14985
+ ...newIds
14986
+ ] : previousIds;
14987
+ if (!sameSelection || newIds.length) setResolvedResourceOrder({
14988
+ resourceId: currentObject?.tinuuid,
14989
+ kitUuid,
14990
+ ids: resourceIds
14991
+ });
14992
+ const allMaterials = enabled ? [
14993
+ ...currentObject?.materials ?? [],
14994
+ ...resourceIds.flatMap((id)=>resolvedMaterials.get(id) ?? [])
14995
+ ] : [];
14996
+ const seen = new Set();
14997
+ return allMaterials.flatMap((material, index)=>{
14998
+ if (!material.hid || !material.native?.glbUrl || seen.has(material.hid)) return [];
14999
+ seen.add(material.hid);
15000
+ return [
15001
+ {
15002
+ material,
15003
+ number: index + 1
15004
+ }
15005
+ ];
15006
+ });
15007
+ }
14878
15008
  function panelCellKey(cell) {
14879
15009
  return `${cell.x},${cell.y}`;
14880
15010
  }
@@ -15043,7 +15173,8 @@ function usePanelSession(enabled, introduce) {
15043
15173
  const firstMaterial = currentObject?.materials?.[0];
15044
15174
  const isPhone = useMediaQuery('(max-width: 639px)');
15045
15175
  const composition = usePanelComposition(tinuuid, firstMaterial?.hid ?? '', introduce && isPhone);
15046
- const materials = enabled ? currentObject?.materials?.filter((candidate)=>candidate.hid && candidate.native?.glbUrl) ?? [] : [];
15176
+ const entries = usePanelMaterials(currentObject, enabled && viewerDialogOpen);
15177
+ const materials = entries.map((entry)=>entry.material);
15047
15178
  const queries = useQueries({
15048
15179
  queries: materials.map((material)=>({
15049
15180
  ...panelModelQuery(material.native.glbUrl),
@@ -15053,7 +15184,7 @@ function usePanelSession(enabled, introduce) {
15053
15184
  const base = queries[materials.findIndex((material)=>material.hid === firstMaterial?.hid)]?.data;
15054
15185
  const options = materials.map((material, index)=>({
15055
15186
  material,
15056
- number: (currentObject?.materials?.indexOf(material) ?? index) + 1,
15187
+ number: entries[index].number,
15057
15188
  model: queries[index]?.data,
15058
15189
  loading: queries[index]?.isFetching ?? false,
15059
15190
  error: queries[index]?.isError ?? false
@@ -17314,17 +17445,6 @@ function Room() {
17314
17445
  ]
17315
17446
  });
17316
17447
  }
17317
- async function layoutGetConfig(data, config = {}) {
17318
- const { client: request = client_client, ...requestConfig } = config;
17319
- const requestData = data;
17320
- const res = await request({
17321
- method: "POST",
17322
- url: "/layout/GetConfig",
17323
- data: requestData,
17324
- ...requestConfig
17325
- });
17326
- return res.data;
17327
- }
17328
17448
  const HDR_NEUTRAL_LINK_TYPE = 'hdr_neutral';
17329
17449
  const ROOM_VIEWER_CONFIG_QUERY_KEY = [
17330
17450
  'room-viewer',
@@ -17344,7 +17464,7 @@ function getNeutralHdrUrl(config) {
17344
17464
  function RemoteNeutralHdrEnvironment() {
17345
17465
  const configQuery = react_query_useQuery({
17346
17466
  queryKey: ROOM_VIEWER_CONFIG_QUERY_KEY,
17347
- queryFn: ()=>layoutGetConfig(),
17467
+ queryFn: ()=>layoutControllerReadLayoutConfig(),
17348
17468
  staleTime: 1 / 0
17349
17469
  });
17350
17470
  if (configQuery.isPending) return null;
@@ -17892,9 +18012,24 @@ function AR({ className, buttonClassName, buttonLeadingIcon, buttonLabel, button
17892
18012
  setIsSceneExporting(true);
17893
18013
  const clone = sceneResource.clone(true);
17894
18014
  clone.position.set(0, 0, 0);
18015
+ clone.quaternion.identity();
18016
+ clone.updateMatrix();
18017
+ clone.updateMatrixWorld(true);
17895
18018
  if (isIOS) {
18019
+ clone.rotation.set(-Math.PI / 2, 0, 0);
18020
+ clone.updateMatrix();
18021
+ clone.updateMatrixWorld(true);
17896
18022
  const usdzExporter = new USDZExporter();
17897
- const usdzBuffer = await usdzExporter.parseAsync(clone);
18023
+ const usdzBuffer = await usdzExporter.parseAsync(clone, {
18024
+ ar: {
18025
+ anchoring: {
18026
+ type: 'plane'
18027
+ },
18028
+ planeAnchoring: {
18029
+ alignment: 'vertical'
18030
+ }
18031
+ }
18032
+ });
17898
18033
  const usdzFile = new File([
17899
18034
  usdzBuffer
17900
18035
  ], 'scene.usdz', {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@neurodyn/react-room-viewer",
3
3
  "type": "module",
4
- "version": "0.0.24",
4
+ "version": "0.0.26",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },