Autoforge Viewer画布在打开兄弟容器后无法调整大小。

huangapple go评论85阅读模式
英文:

Autoforge Viewer canvas won't resize after open sibling container

问题

在876像素宽度时,父元素的flex-direction属性变为column。当我打开参数容器,然后在宽度低于876像素时关闭参数容器,Forge Viewer的画布大小不会重新调整,导致出现白色空白区域。

enter image description here

enter image description here

enter image description here

forgeView.js

import React, { Component } from 'react';
import Script from 'react-load-script';
import { connect } from 'react-redux';
import { getActiveProject } from '../reducers/mainReducer';
import './forgeView.css';
import Message from './message';
import repo from '../Repository';
import { viewerCss, viewerJs } from './shared';
import ParametersContainer from './parametersContainer';
import './parametersContainer.css';

let Autodesk = null;

export class ForgeView extends Component {

    constructor(props) {
        super(props);

        this.viewerDiv = React.createRef();
        this.viewer = null;
    }

    resizeViewer() {
        if (this.viewer && this.viewerDiv.current) {
            const container = this.viewerDiv.current;
            this.viewer.resize();
        }
    }

    handleScriptLoad() {

        const options = repo.hasAccessToken() ?
            { accessToken: repo.getAccessToken() } :
            { env: 'Local' };

        Autodesk = window.Autodesk;

        const container = this.viewerDiv.current;
        this.viewer = new Autodesk.Viewing.GuiViewer3D(container);

        // uncomment this for Viewer debugging
        // this.viewer.debugEvents(true);

        Autodesk.Viewing.Initializer(options, this.handleViewerInit.bind(this));
        window.addEventListener("resize", this.resizeViewer.bind(this));
    }

    handleViewerInit() {
        const errorCode = this.viewer.start();
        if (errorCode)
            return;

        // orient camera in the same way as it's on the thumbnail
        // corresponding to ViewOrientationTypeEnum.kIsoTopRightViewOrientation
        const viewer = this.viewer;
        const forgeSpinner = document.getElementsByClassName("forge-spinner")[0]
        const image = forgeSpinner.children[1]
        image.src = "";
        this.viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, (event) => {

            const viewCubeExtensionId = "Autodesk.ViewCubeUi";

            // this is not perfect, because the view transition is visible, so it's a place to improve someday
            if (event.extensionId === viewCubeExtensionId) {

                const viewCubeUI = event.target.getExtension(viewCubeExtensionId);
                viewCubeUI.setViewCube("front top right");

                viewer.removeEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT);
            }

            const explodeExtension = viewer.getExtension('Autodesk.Explode');
            const sectionExtension = viewer.getExtension('Autodesk.Section');
            const modelExtension = viewer.getExtension('Autodesk.ModelStructure');
            const propertiesExtension = viewer.getExtension('Autodesk.PropertiesManager');

            explodeExtension.unload();
            sectionExtension.unload();
            modelExtension.unload();
            propertiesExtension.unload();

        });

        // skip loading of svf when there is no active project svf
        if (!this.props.activeProject.svf)
            return;

        Autodesk.Viewing.Document.load(
            this.getSvfUrl(), this.onDocumentLoadSuccess.bind(this), () => { }
        );
    }

    componentDidMount() {
        this.resizeViewer();
    }

    componentDidUpdate(prevProps) {
        if (Autodesk && (this.props.activeProject.svf !== prevProps.activeProject.svf)) {
            Autodesk.Viewing.Document.load(
                this.getSvfUrl(), this.onDocumentLoadSuccess.bind(this), () => { }
            );
        }

        this.resizeViewer();


    }

    componentWillUnmount() {
        if (this.viewer) {
            this.viewer.finish();
            this.viewer = null;
            Autodesk.Viewing.shutdown();
        }

        window.removeEventListener("resize", this.resizeViewer.bind(this));
    }

    getSvfUrl() {
        return this.props.activeProject.svf + `/bubble.json`;
    }

    onDocumentLoadSuccess(viewerDocument) {
        const defaultModel = viewerDocument.getRoot().getDefaultGeometry();
        this.viewer.loadDocumentNode(viewerDocument, defaultModel).then(() => {
            this.viewer.fitToView();
        })
    }

    render() {

        return (
            <div className="modelContainer fullheight">
                <Message />
                <div className="viewer" id="ForgeViewer">
                    <div ref={this.viewerDiv}></div>
                    <link rel="stylesheet" type="text/css" href={viewerCss} />
                    <Script url={viewerJs} onLoad={this.handleScriptLoad.bind(this)} />
                </div>
            </div>
        );
    }
}

我查阅了其他类似的问题,但对我没有起作用。

英文:

I have 2 element rendering in a same parent element one of them is a parameter container that can open and close and other is forge viewer. At 876px width this parent element gets flex-direction:column ; . When i open parameters container and go below 876px and close the parameter container forge viewer canvas size wont resize and white blank space appears.

enter image description here

enter image description here

enter image description here

forgeView.js

import React, { Component } from &#39;react&#39;;
import Script from &#39;react-load-script&#39;;
import {connect} from &#39;react-redux&#39;;
import { getActiveProject } from &#39;../reducers/mainReducer&#39;;
import &#39;./forgeView.css&#39;;
import Message from &#39;./message&#39;;
import repo from &#39;../Repository&#39;;
import { viewerCss, viewerJs } from &#39;./shared&#39;;
import ParametersContainer from &#39;./parametersContainer&#39;
import &#39;./parametersContainer.css&#39;
let Autodesk = null;
export class ForgeView extends Component {
constructor(props){
super(props);
this.viewerDiv = React.createRef();
this.viewer = null;
}
resizeViewer() {
if (this.viewer &amp;&amp; this.viewerDiv.current) {
const container = this.viewerDiv.current;
this.viewer.resize()
}   
}
handleScriptLoad() {
const options = repo.hasAccessToken() ?
{ accessToken: repo.getAccessToken() } :
{ env: &#39;Local&#39; };
Autodesk = window.Autodesk;
const container = this.viewerDiv.current;
this.viewer = new Autodesk.Viewing.GuiViewer3D(container);
// uncomment this for Viewer debugging
//this.viewer.debugEvents(true);
Autodesk.Viewing.Initializer(options, this.handleViewerInit.bind(this));
window.addEventListener(&quot;resize&quot;, this.resizeViewer.bind(this));
}
handleViewerInit() {
const errorCode = this.viewer.start();
if (errorCode)
return;
// orient camera in the same way as it&#39;s on the thumbnail
// corresponding to ViewOrientationTypeEnum.kIsoTopRightViewOrientation
const viewer = this.viewer;
const forgeSpinner = document.getElementsByClassName(&quot;forge-spinner&quot;)[0]
const image = forgeSpinner.children[1]
image.src = &quot;&quot;;
this.viewer.addEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT, (event) =&gt; {
const viewCubeExtensionId = &quot;Autodesk.ViewCubeUi&quot;;
// this is not perfect, because the view transition is visible, so it&#39;s a place to improve someday
if (event.extensionId === viewCubeExtensionId) {
const viewCubeUI = event.target.getExtension(viewCubeExtensionId);
viewCubeUI.setViewCube(&quot;front top right&quot;);
viewer.removeEventListener(Autodesk.Viewing.EXTENSION_LOADED_EVENT);
}
const explodeExtension = viewer.getExtension(&#39;Autodesk.Explode&#39;);
const sectionExtension = viewer.getExtension(&#39;Autodesk.Section&#39;);
const modelExtension = viewer.getExtension(&#39;Autodesk.ModelStructure&#39;);
const propertiesExtension = viewer.getExtension(&#39;Autodesk.PropertiesManager&#39;);
explodeExtension.unload();
sectionExtension.unload();
modelExtension.unload();
propertiesExtension.unload();
});
// skip loading of svf when there is no active project svf
if (!this.props.activeProject.svf)
return;
Autodesk.Viewing.Document.load(
this.getSvfUrl(), this.onDocumentLoadSuccess.bind(this), () =&gt; {}
);
}
componentDidMount() {
this.resizeViewer();
}
componentDidUpdate(prevProps) {
if (Autodesk &amp;&amp; (this.props.activeProject.svf !== prevProps.activeProject.svf)) {
Autodesk.Viewing.Document.load(
this.getSvfUrl(), this.onDocumentLoadSuccess.bind(this), () =&gt; {}
);
}
this.resizeViewer();
}
componentWillUnmount() {
if (this.viewer) {
this.viewer.finish();
this.viewer = null;
Autodesk.Viewing.shutdown();
}
window.removeEventListener(&quot;resize&quot;, this.resizeViewer.bind(this));
}
getSvfUrl() {
return this.props.activeProject.svf + `/bubble.json`;
}
onDocumentLoadSuccess(viewerDocument) {
const defaultModel = viewerDocument.getRoot().getDefaultGeometry();
this.viewer.loadDocumentNode(viewerDocument, defaultModel).then(() =&gt; {
this.viewer.fitToView();
})
}
render() {
return (
&lt;div className=&quot;modelContainer fullheight&quot;&gt;
&lt;Message/&gt;
&lt;div className=&quot;viewer&quot; id=&quot;ForgeViewer&quot;&gt;
&lt;div ref={this.viewerDiv}&gt;&lt;/div&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href={ viewerCss } /&gt;
&lt;Script url={ viewerJs } onLoad={this.handleScriptLoad.bind(this)} /&gt;
&lt;/div&gt;
&lt;/div&gt;
);
}
}  

I look up other similar questions but that didn't work for me.

答案1

得分: 0

我看到你已经调用了 viewer.resize,这应该会相应地更新渲染上下文。如果这不起作用,我建议尝试以下操作:

  • 当你进入“损坏”状态,查看器未渲染整个对象时,尝试打开浏览器控制台,然后输入 NOP_VIEWER.resize();如果这解决了问题,可能是你的代码没有在正确的时间调用 viewer.resize 方法。

  • 你可能在打开/关闭参数界面时使用了动画吗?如果是这样,尝试禁用它们,或确保在动画完成后调用 viewer.resize

  • 检查浏览器控制台,看看是否有任何与不完整渲染相关的错误或警告。

英文:

I see that you're already calling viewer.resize which should update the rendering context accordingly. If that's not working, I'd suggest to try the following:

  • when you end up in the "broken" state where the viewer is not rendering the entire object, try opening the browser console, and type NOP_VIEWER.resize(); if that resolves the issue, it's possible that your code isn't calling the viewer.resize method at the right time

  • are you perhaps using any animations when opening/closing the parameters UI? If so, try and disable them, or make sure that the viewer.resize is called after the animation is complete

  • check the browser console to see if there are any errors or warnings that could be related to the incomplete rendering

huangapple
  • 本文由 发表于 2023年7月27日 21:28:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76780254.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定