viewer.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. var nd_viewCtrl = {
  2. src: '', // https://zhizaoyun-static.oss-cn-hangzhou.aliyuncs.com/tuzhitongwps/ModelFile/C9Z8165213949311
  3. allTags: [],
  4. hidebtnCfg: [],//隐藏的按钮对应按钮id0
  5. _opt:{},
  6. fingerHttp: '',
  7. tagRelateConfig: true,//v5.0x-,多配置是否切换批注点显示
  8. init: function (opt) {
  9. this.src = opt.src;
  10. this._opt = opt;
  11. this.allTags = opt.tags;
  12. if(window.location.hostname == 'api.3dopen.cn' || window.location.hostname == 'apiyfbtest.3dopen.cn'){
  13. document.querySelector("#iframeDiv").innerHTML = '<iframe id="viewer" src="indexcdn.html" allowFullScreen></iframe>';
  14. }else{
  15. document.querySelector("#iframeDiv").innerHTML = '<iframe id="viewer" src="index.html" allowFullScreen></iframe>';
  16. }
  17. },
  18. initLoad: function () { //加载完成
  19. console.log('model loaded!');
  20. this.getInstance();
  21. this._opt && this._opt.loadedBack && this._opt.loadedBack();
  22. },
  23. loadFaild: function () { //资源加载错误
  24. console.log('model loaded error!');
  25. },
  26. getModelBgImg: function () { //模型背景图
  27. return this.bgImg;
  28. },
  29. getTags: function () {
  30. return this.allTags;
  31. },
  32. checkTags: function (cc) {//检查批注的逻辑
  33. if (this._opt.onCheck)
  34. this._opt.onCheck(cc);
  35. else cc();
  36. },
  37. addTags: function (a, i, cc) { //增加标记回调 (增加的标记,截图,回调方法)
  38. if (this._opt.onAddTag)
  39. this._opt.onAddTag(a, i, cc);
  40. else cc();
  41. },
  42. delTags: function (uid) { //删除标记 单个序号或者数组
  43. var _contentWindow = document.getElementById("viewer").contentWindow;
  44. if (_contentWindow) {
  45. _contentWindow.nd_delTags(uid);
  46. }
  47. },
  48. beDelTag: function (uid, cc) {//被删除标记
  49. if (this._opt.onDel)
  50. this._opt.onDel(uid, cc);
  51. else cc();
  52. },
  53. enterTag: function () { //进入标记模式
  54. var _contentWindow = document.getElementById("viewer").contentWindow;
  55. if (_contentWindow) {
  56. _contentWindow.nd_enterTag();
  57. }
  58. },
  59. isEnterTag: function () { //是否在标记模式
  60. var _contentWindow = document.getElementById("viewer").contentWindow;
  61. if (_contentWindow) {
  62. return _contentWindow.nd_isEnterTag();
  63. }
  64. },
  65. selectTag: function (uuid) { //打开标记模式
  66. document.getElementById("viewer").contentWindow.nd_selectTag(uuid);
  67. },
  68. exitTag: function () {//退出标记
  69. },
  70. beSelectTag: function (i) {//被选择标记
  71. this._opt.onSelect && this._opt.onSelect(i);
  72. },
  73. addPicTag: function (d, i, cc) {//增加的图片标记
  74. if (this._opt.onAddPicTag)
  75. this._opt.onAddPicTag(d, i, cc);
  76. else cc(i);
  77. },
  78. addVideoTag: function (d, i,v, cc) {//增加的图片标记
  79. var file= v.get("file");
  80. if (this._opt.onAddVideoTag){
  81. this._opt.onAddVideoTag(d, i, cc);
  82. }
  83. else {
  84. // window.urlVideo=window.urlVideo=='models/v2.mp4'?'models/v.mp4':'models/v2.mp4';
  85. var urlVideo=this.getFileURL(file);
  86. cc(i,urlVideo);
  87. }
  88. },
  89. editVideoTag: function (d, i,v, cc) { // 编辑图问批注 d: 批注内容 i:批注图片 cc:通知可进行下一步
  90. var file= v.get("file");
  91. console.log('📌编辑批注info、video=========', d, i);
  92. if (this._opt.onEditVideoTag){
  93. this._opt.onEditVideoTag(d, i, cc);
  94. }
  95. else {
  96. var type= v.get("type");
  97. if(type=="file"){
  98. var file=v.get("file");
  99. var urlVideo= this.getFileURL(file);
  100. cc(i,urlVideo);
  101. }else{
  102. var urlVideo=v.get("src");
  103. cc(i,urlVideo);
  104. }
  105. }
  106. },
  107. editPicTag: function (d, i, cc) { // 编辑图问批注 d: 批注内容 i:批注图片 cc:通知可进行下一步
  108. console.log('📌编辑批注info、img=========', d, i);
  109. cc && cc(i);
  110. },
  111. screenshot: function (callBack) {//截图
  112. var _contentWindow = document.getElementById("viewer").contentWindow;
  113. if (_contentWindow) {
  114. _contentWindow.nd_screenCapture(function (base64Img) {
  115. callBack&&callBack(base64Img);
  116. console.log(base64Img);
  117. });
  118. }
  119. },
  120. getScreenCaptureByData: function(cc, data) { // 新版可视包围盒截图
  121. var _contentWindow = document.getElementById("viewer").contentWindow;
  122. if (_contentWindow) {
  123. _contentWindow.nd_getScreenCaptureByData(function (base64Img) {
  124. cc && cc(base64Img);
  125. },data);
  126. }
  127. },
  128. screensbounding: function (callBack) {//包围盒截图
  129. var _contentWindow = document.getElementById("viewer").contentWindow;
  130. if (_contentWindow) {
  131. _contentWindow.nd_screenBounding(function (base64Img) {
  132. callBack&&callBack(base64Img);
  133. console.log(base64Img);
  134. });
  135. }
  136. },
  137. getScreenCaptureByData: function (cc, data) { // 新版可视包围盒截图
  138. var _contentWindow = document.getElementById("viewer").contentWindow;
  139. if (_contentWindow) {
  140. _contentWindow.nd_getScreenCaptureByData(function (base64Img) {
  141. cc && cc(base64Img);
  142. }, data);
  143. }
  144. },
  145. configImgUpload: function (itemInfo, img) {
  146. this._opt.configImgUpload && this._opt.configImgUpload(itemInfo, img);
  147. },
  148. log: function (str) {//提示框
  149. alert(str);
  150. },
  151. getInstance:function(){
  152. _contentWindow = document.getElementById("viewer").contentWindow;
  153. this.Instance=_contentWindow;
  154. if (_contentWindow ) {
  155. for (var i in _contentWindow) {
  156. if (String(i).indexOf('nd_')==0 &&typeof _contentWindow[i] === 'function') {
  157. nd_viewCtrl[i]=_contentWindow[i];
  158. }
  159. }
  160. }
  161. },
  162. selectChangeEvent:function(type){
  163. this._opt.selectChangeEvent && this._opt.selectChangeEvent(type);
  164. },
  165. getFileURL:function(file) {
  166. var url = null;
  167. if (window.createObjectURL != undefined) { // basic
  168. url = window.createObjectURL(file);
  169. console.log("window.createObjectURL(file)",url);
  170. }
  171. else if (window.webkitURL!= undefined) { // webkit or chrome
  172. url = window.webkitURL.createObjectURL(file);
  173. console.log("window.webkitURL.createObjectURL(file)",url);
  174. }else if (window.URL != undefined) { // mozilla(firefox)
  175. url = window.URL.createObjectURL(file);
  176. console.log("window.URL.createObjectURL(file)",url);
  177. }
  178. return url;
  179. },
  180. addLineTag: function(d, i, cc) { // 添加引线批注方法 d:批注信息,i:批注图片,cc回调参数
  181. console.log('新增引线==========', d, i);
  182. cc && cc();
  183. },
  184. editLineTag: function(d, i, cc) { // 编辑引线批注
  185. console.log('编辑引线==========', d, i);
  186. cc && cc();
  187. },
  188. beDelLineTag: function (i, cc) {
  189. console.log('删除引线========', i);
  190. cc && cc();
  191. },
  192. delLineTag: function(i) { // 删除对应批注数据
  193. var _contentWindow = document.getElementById("viewer").contentWindow;
  194. if (_contentWindow) {
  195. _contentWindow.nd_delLineTag(i);
  196. }
  197. },
  198. addModelview: function (d, i, cc) { // 添加视图
  199. //console.log('添加视图==========', d, i);
  200. cc(i)
  201. },
  202. delModelview: function (id, cc) { // 删除视图
  203. //console.log('删除视图==========', id);
  204. cc()
  205. },
  206. renameModelview: function (id, viewport) { // 编辑视图
  207. //console.log('编辑视图==========', id, viewport);
  208. },
  209. }