英文:
Autoforge Viewer canvas won't resize after open sibling container
问题
在876像素宽度时,父元素的flex-direction
属性变为column
。当我打开参数容器,然后在宽度低于876像素时关闭参数容器,Forge Viewer的画布大小不会重新调整,导致出现白色空白区域。
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.
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 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 theviewer.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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论