var nd_viewCtrl = {
src: '', // https://zhizaoyun-static.oss-cn-hangzhou.aliyuncs.com/tuzhitongwps/ModelFile/C9Z8165213949311
allTags: [],
hidebtnCfg: [],//隐藏的按钮对应按钮id0
_opt:{},
fingerHttp: '',
tagRelateConfig: true,//v5.0x-,多配置是否切换批注点显示
init: function (opt) {
this.src = opt.src;
this._opt = opt;
this.allTags = opt.tags;
if(window.location.hostname == 'api.3dopen.cn' || window.location.hostname == 'apiyfbtest.3dopen.cn'){
document.querySelector("#iframeDiv").innerHTML = '';
}else{
document.querySelector("#iframeDiv").innerHTML = '';
}
},
initLoad: function () { //加载完成
console.log('model loaded!');
this.getInstance();
this._opt && this._opt.loadedBack && this._opt.loadedBack();
},
loadFaild: function () { //资源加载错误
console.log('model loaded error!');
},
getModelBgImg: function () { //模型背景图
return this.bgImg;
},
getTags: function () {
return this.allTags;
},
checkTags: function (cc) {//检查批注的逻辑
if (this._opt.onCheck)
this._opt.onCheck(cc);
else cc();
},
addTags: function (a, i, cc) { //增加标记回调 (增加的标记,截图,回调方法)
if (this._opt.onAddTag)
this._opt.onAddTag(a, i, cc);
else cc();
},
delTags: function (uid) { //删除标记 单个序号或者数组
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_delTags(uid);
}
},
beDelTag: function (uid, cc) {//被删除标记
if (this._opt.onDel)
this._opt.onDel(uid, cc);
else cc();
},
enterTag: function () { //进入标记模式
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_enterTag();
}
},
isEnterTag: function () { //是否在标记模式
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
return _contentWindow.nd_isEnterTag();
}
},
selectTag: function (uuid) { //打开标记模式
document.getElementById("viewer").contentWindow.nd_selectTag(uuid);
},
exitTag: function () {//退出标记
},
beSelectTag: function (i) {//被选择标记
this._opt.onSelect && this._opt.onSelect(i);
},
addPicTag: function (d, i, cc) {//增加的图片标记
if (this._opt.onAddPicTag)
this._opt.onAddPicTag(d, i, cc);
else cc(i);
},
addVideoTag: function (d, i,v, cc) {//增加的图片标记
var file= v.get("file");
if (this._opt.onAddVideoTag){
this._opt.onAddVideoTag(d, i, cc);
}
else {
// window.urlVideo=window.urlVideo=='models/v2.mp4'?'models/v.mp4':'models/v2.mp4';
var urlVideo=this.getFileURL(file);
cc(i,urlVideo);
}
},
editVideoTag: function (d, i,v, cc) { // 编辑图问批注 d: 批注内容 i:批注图片 cc:通知可进行下一步
var file= v.get("file");
console.log('📌编辑批注info、video=========', d, i);
if (this._opt.onEditVideoTag){
this._opt.onEditVideoTag(d, i, cc);
}
else {
var type= v.get("type");
if(type=="file"){
var file=v.get("file");
var urlVideo= this.getFileURL(file);
cc(i,urlVideo);
}else{
var urlVideo=v.get("src");
cc(i,urlVideo);
}
}
},
editPicTag: function (d, i, cc) { // 编辑图问批注 d: 批注内容 i:批注图片 cc:通知可进行下一步
console.log('📌编辑批注info、img=========', d, i);
cc && cc(i);
},
screenshot: function (callBack) {//截图
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_screenCapture(function (base64Img) {
callBack&&callBack(base64Img);
console.log(base64Img);
});
}
},
getScreenCaptureByData: function(cc, data) { // 新版可视包围盒截图
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_getScreenCaptureByData(function (base64Img) {
cc && cc(base64Img);
},data);
}
},
screensbounding: function (callBack) {//包围盒截图
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_screenBounding(function (base64Img) {
callBack&&callBack(base64Img);
console.log(base64Img);
});
}
},
getScreenCaptureByData: function (cc, data) { // 新版可视包围盒截图
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_getScreenCaptureByData(function (base64Img) {
cc && cc(base64Img);
}, data);
}
},
configImgUpload: function (itemInfo, img) {
this._opt.configImgUpload && this._opt.configImgUpload(itemInfo, img);
},
log: function (str) {//提示框
alert(str);
},
getInstance:function(){
_contentWindow = document.getElementById("viewer").contentWindow;
this.Instance=_contentWindow;
if (_contentWindow ) {
for (var i in _contentWindow) {
if (String(i).indexOf('nd_')==0 &&typeof _contentWindow[i] === 'function') {
nd_viewCtrl[i]=_contentWindow[i];
}
}
}
},
selectChangeEvent:function(type){
this._opt.selectChangeEvent && this._opt.selectChangeEvent(type);
},
getFileURL:function(file) {
var url = null;
if (window.createObjectURL != undefined) { // basic
url = window.createObjectURL(file);
console.log("window.createObjectURL(file)",url);
}
else if (window.webkitURL!= undefined) { // webkit or chrome
url = window.webkitURL.createObjectURL(file);
console.log("window.webkitURL.createObjectURL(file)",url);
}else if (window.URL != undefined) { // mozilla(firefox)
url = window.URL.createObjectURL(file);
console.log("window.URL.createObjectURL(file)",url);
}
return url;
},
addLineTag: function(d, i, cc) { // 添加引线批注方法 d:批注信息,i:批注图片,cc回调参数
console.log('新增引线==========', d, i);
cc && cc();
},
editLineTag: function(d, i, cc) { // 编辑引线批注
console.log('编辑引线==========', d, i);
cc && cc();
},
beDelLineTag: function (i, cc) {
console.log('删除引线========', i);
cc && cc();
},
delLineTag: function(i) { // 删除对应批注数据
var _contentWindow = document.getElementById("viewer").contentWindow;
if (_contentWindow) {
_contentWindow.nd_delLineTag(i);
}
},
addModelview: function (d, i, cc) { // 添加视图
//console.log('添加视图==========', d, i);
cc(i)
},
delModelview: function (id, cc) { // 删除视图
//console.log('删除视图==========', id);
cc()
},
renameModelview: function (id, viewport) { // 编辑视图
//console.log('编辑视图==========', id, viewport);
},
}