을 기본 재질을 변경할 수 뷰어가 자동으로 내가</p> <p>구조가로드 일부 요소의 재료의 변경에 문제가
모델의 재료가 변경된 것을 볼 수 있기 때문에 작동하지만, 문제는 ~ 1-2 초 후에 재료가 다시 채워지는 것입니다.
이 코드는 수동으로 실행해도 재료를 변경할 수 없습니다. 뷰어이 2 초 후 재료의 변화를 잠그는 이유
질문은, 어떻게 그것을
을 방지하기 위해 그리고 어쩌면 당신은 내가 예를 들어, 재질 변화에 더 잘 할 수있는 걸 말할 수있을 것입니다. GEOMETRY_LOAD 이후 코드를 실행하는 것이 더 좋을 수도 있습니다. (GEOMETRY_LOADED_EVENT에서 변경 이벤트가 OBJECT_TREE_CREATED_EVENT 때
는 "가끔"하지만 때때로 잘 작동합니다 : 첫 번째 모델
렌더링하기 전에 최고의
가힌트 ........ 변화 재료가 될 것입니다 재료는 모델 작업의 끝까지 머물러 있습니다.) 대부분 OBJECT_TREE_CREATED 이후에 내 방법을 실행할 때 (심지어 수동으로 실행하지 않아도 재료가 어떤 식 으로든 잠겨 있습니다). 그래서
내가 어떤 도움
를위한 감사합니다 ======================= 그 문제가 GEOMETRY_LOAD의 시간과 OBJECT_TREE_CREATED 사이에 의심 ======= 전체 코드 ==============================
index.html을
<div id="main">
<div id="MyViewerDiv"></div>
<button id="open-nav-button" onClick="showDocInfo()">test</button>
</div>
<script src="https://developer.api.autodesk.com/derivativeservice/v2/viewers/three.min.js"></script>
<script src="https://developer.api.autodesk.com/derivativeservice/v2/viewers/viewer3D.min.js"></script>
<script type="text/javascript" src="lib/jquery.min.js"></script>
<script src="js/autodesk-viewer.js"></script>
<script src="js/extension/test-extension.js"></script>
<script>
const autodeskViewer = new AutodeskViewer()
const showDocInfo =() => {
autodeskViewer.showDocInfo()
}
</script>
오토 데스크 - viewer.js
var AutodeskViewer = (function() {
function AutodeskViewer() {
var _this = this;
this.urn = 'urn:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6Zm9yZ2UtamF2YS1zYW1wbGUtYXBwLTFzcGduazdqcWpxdjhmYXV0YmNzd2R0cGdvN3VtNWY1L1BPQy1Gb3JnZS1JVCUyMDIwMTclMjBSdWNoXzEwMDUxNy5ud2Q';
this.initializeViewer = function (containerId, documentId) {
_this.viewerApp = new Autodesk.Viewing.ViewingApplication(containerId);
var config = {
extensions: ['TestExtension']
};
_this.viewerApp.registerViewer(_this.viewerApp.k3D, Autodesk.Viewing.Private.GuiViewer3D, config);
_this.viewerApp.loadDocument(documentId, _this.onDocumentLoadSuccess, _this.onDocumentLoadFailure);
}
this.onDocumentLoadSuccess = function (doc) {
const viewables = _this.viewerApp.bubble.search(av.BubbleNode.MODEL_NODE);
if (viewables.length === 0) {
return;
}
_this.viewerApp.selectItem(viewables[0].data, _this.onItemLoadSuccess, _this.onItemLoadFail);
_this.viewer3d = _this.viewerApp.getCurrentViewer();
}
this.onDocumentLoadFailure = (viewerErrorCode) => {}
this.onItemLoadSuccess = (viewer) => {
_this.viewer = viewer
}
this.onItemLoadFail = (errorCode) => {}
this.initialize =() => {
var options = {
env: 'AutodeskProduction',
getAccessToken: _this.getToken,
refreshToken: _this.getToken
};
Autodesk.Viewing.Initializer(options, _this.initCallback);
};
this.initCallback = function() {
_this.initializeViewer('MyViewerDiv', _this.urn, '3d');
};
this.getToken = function (onGetAccessToken) {
$.get("forge/oauth/token")
.done(function (data) {
token = data
onGetAccessToken(token, 60 * 60);
})
.fail(function (error) {
console.log('ERROR', error);
});
};
this.showDocInfo = function() {};
this.initialize();
}
return AutodeskViewer;
}());
,210 테스트 extension.js 지금까지
var _self;
var _viewer;
var _tempValue = 0;
function TestExtension(viewer, options) {
Autodesk.Viewing.Extension.call(this, viewer, options);
_self = this;
_viewer = viewer;
}
const changeModelMaterial =() => {
// _tempValue++;
// if (_tempValue == 2) {
const elements = [4340, 4342, 4344, 4346, 4348, 4367, 4371, 4375, 4380, 4452, 4468, 4488, 4503, 4517, 4520, 4522, 4524, 4526, 4528, 4530]
changeAllElementsMaterial(new THREE.Color(0.5, 0.5, 0.5))
setMaterialOfDbIds(elements)
_tempValue = 0
// }
}
const changeAllElementsMaterial = (color) => {
var fragmentList = _viewer.model.getFragmentList();
for (let materialId of fragmentList.materialids) {
if (fragmentList.materialmap[materialId]) {
fragmentList.materialmap[materialId].map = null
fragmentList.materialmap[materialId].color = color
fragmentList.materialmap[materialId].needsUpdate = true;
}
}
_viewer.impl.invalidate(true);
}
const setMaterialOfDbIds = (dbIds) => {
var colorM = new THREE.MeshPhongMaterial({
color: new THREE.Color(0xAB00EE)
});
for (let dbId of dbIds) {
_viewer.model.getData().instanceTree.enumNodeFragments(dbId, function (fragId) {
_viewer.model.getFragmentList().setMaterial(fragId, colorM);
});
}
_viewer.impl.invalidate(true);
}
TestExtension.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
TestExtension.prototype.constructor = TestExtension;
TestExtension.prototype.load = function() {
_viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, changeModelMaterial)
// _viewer.addEventListener(Autodesk.Viewing.GEOMETRY_LOADED_EVENT, changeModelMaterial)
return true
};
TestExtension.prototype.unload = function() {
return true
};
Autodesk.Viewing.theExtensionManager.registerExtension('TestExtension', TestExtension);
이 좋아, 이제 난'두 개의 이벤트 (OBJECT_TREE_CREATED_EVENT 및 GEOMETRY_LOADED_EVENT) 후 내 물건을 해고 작동 왜 pls는 뭔가 더 말할 이해한다면,이 변화는 여전히 같은 동작을 . 처음에는 재료가 처음 2-3 초 만에 바뀔 수있는 이유를 알아야한다고 생각합니다. –
재현 가능한 샘플을 제공 할 수 있다면 한번 살펴 보겠습니다. 자료 데모를 사용해 보셨습니까? 확실히 거기에서 잘 작동하므로 뭔가 잘못하고 있어야합니다 ... 또한 뷰어를 살펴볼 수도 있습니다 .setThemingColor : https://stackoverflow.com/questions/38534862/autodesk-forge-viewer-does-viewer-setthemingcolor- work-on-a-converted-dwg 파일 –
내 질문을 업데이트했습니다. 이제 모든 코드를 볼 수 있습니다. 직접 사용해 볼 수도 있습니다. 이제 확장 기능이 OBJECT_TREE_CREATED_EVENT에 대한 이벤트 리스너를 추가하여로드됩니다. 그래서 내가하고 싶은 일은 가끔 있습니다. load 메서드에서 다른 listener의 주석을 제거하고 changeModelMaterial 메서드에서 간단한 간단한 트릭을 수행하면 재질이 업데이트되고 ~ 2 초 후에 기본 리스너로 되돌아갑니다. –