简体中文
主题
简体中文
主题
本页描述宿主页面直接调用的全局插件接口。
当你引入:
<script src="https://www.kivicube.com/lib/iframe-plugin.js"></script>宿主页面可直接使用全局对象:
window.kivicubeIframePlugin常见调用通常写成:
kivicubeIframePlugin.openKivicubeScene(...)openKivicubeScene(
iframe: HTMLIFrameElement,
props?: SceneOpenProps,
modifyIframe?: boolean,
): Promise<{
id: string;
allow: string;
src: string;
}>iframe 承载 Kivicube 内容的 iframe DOM。
props 场景打开参数,见下方 SceneOpenProps。
modifyIframe 是否立即把生成后的 id、allow、src 写回到 iframe。
truefalse 时,只返回计算结果,不修改 DOM,适用于Vue/React组件封装。interface OpenResult {
id: string;
allow: string;
src: string;
}destroyKivicubeScene(iframe: HTMLIFrameElement): void它会清理当前 iframe 对应的内部资源。常与把 iframe.src 切到空白页一起使用。
注意:如果要在同一页面切换多个场景,销毁上一个场景时,一定要调用destroyKivicubeScene方法
openKivicubeCollection(
iframe: HTMLIFrameElement,
props?: CollectionOpenProps,
modifyIframe?: boolean,
): Promise<{
id: string;
allow: string;
src: string;
}>与 openKivicubeScene() 基本一致,只是 props 换成合辑版本。
destroyKivicubeCollection(iframe: HTMLIFrameElement): voidinterface SceneOpenProps {
sceneId: string;
hideLogo?: boolean;
hideTitle?: boolean;
hideDownload?: boolean;
cameraPosition?: 'front' | 'back';
hideLoading?: boolean;
hideScan?: boolean;
hideTakePhoto?: boolean;
hideBackground?: boolean;
hideStart?: boolean;
disableOpenUrl?: boolean;
}interface CollectionOpenProps {
collectionId: string;
hideLogo?: boolean;
hideTitle?: boolean;
hideDownload?: boolean;
cameraPosition?: 'front' | 'back';
hideLoading?: boolean;
hideScan?: boolean;
hideBackToScan?: boolean;
hideTakePhoto?: boolean;
hideStart?: boolean;
hideGyroscopePermission?: boolean;
disableOpenUrl?: boolean;
}插件会从 iframe 上读取支持的属性,并同时兼容:
hide-logohideLogodata-hide-logo调用 openKivicubeScene() / openKivicubeCollection() 时,JS 传入的 props 会覆盖 HTML 上的同名属性。
如果页面存在:
<iframe id="kivicubeScene" scene-id="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></iframe>并且该节点在 DOMContentLoaded 触发前已存在,插件会自动执行 openKivicubeScene()。
如果页面存在:
<iframe id="kivicubeCollection" collection-id="xxxxxx"></iframe>则会自动执行 openKivicubeCollection()。
插件会自动写入需要的权限:
xr-spatial-tracking;camera;microphone;autoplay;fullscreen;gyroscope;accelerometer