资讯专栏INFORMATION COLUMN

「翻译」在Forge Viewer上实作简易的模型版本比较

JowayYoung / 3144人阅读

摘要:现在让我们修改这个示例让他可以展示两个同项目但不同版号的模型及。示例执行结果如下这边是这个比较模型的括展代码英文原文

熟悉 BIM360 Team 的朋友可能知道他有一个很牛的模型文档版本比较的功能,但如果模型是放在 Google 云盘或是百度云盘上有可能做到吗?

Autodesk Forge 团队先前写了一个从 Google 云盘的转档示例,这个示例会从 Google 云盘里下载模型文档到你的服务器上,在将它上传到 Forge Data Management 服务上进行转档,同时在转档完成后在浏览器上展示结果。

现在让我们修改这个示例让他可以展示两个同项目但不同版号的 Revit 模型(model A 及 model B)。在 Forge Viewer 里,每个 Revit 构件都会对应到一个 dbId,而这个 dbId 也会对应到一个 Reivt 唯一码(Unique GUID),这个唯一码也是 Forge Viewer 的外部编码(Extenal Id),所以只要在 model A 及 model B 里比对两者间有没有不存在的 Extenal Id,以及比对同一个 External Id 的构件属性里有没有被新增、修改及删除的参数,根据这个思路我们可以将没有修改的构件隐藏起来,有异动的构件以绿色(新增的)、红色(删除的)及橘色(有修改的)来上色,就可以在 Forge Viewer 上做出简单的模型比较功能,原代码可以参考这里,示例可造访这里。

示例执行结果如下:

这边是这个比较模型的括展代码:

</>复制代码

  1. function VersionChanges(viewer, options) {
  2. Autodesk.Viewing.Extension.call(this, viewer, options);
  3. }
  4. VersionChanges.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
  5. VersionChanges.prototype.constructor = VersionChanges;
  6. VersionChanges.prototype.load = function () {
  7. var modelA = this.options.modelA;
  8. var modelB = this.options.modelB;
  9. var removed = {};
  10. var added = {};
  11. var modified = {};
  12. var red = new THREE.Vector4(1, 0, 0, 1);
  13. var green = new THREE.Vector4(0, 0.5, 0, 1);
  14. var orange = new THREE.Vector4(1, 0.6, 0.2, 1);
  15. viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
  16. listElements(function (listA, listB) {
  17. // make all elements as ghost
  18. viewer.isolate(-1);
  19. viewer.clearThemingColors(modelA);
  20. viewer.clearThemingColors(modelB);
  21. for (var extIdA in listA) {
  22. if (listB[extIdA] != null) continue;
  23. var dbIdA = listA[extIdA].dbId;
  24. removed[extIdA] = dbIdA;
  25. console.log("Removed dbId: " + dbIdA);
  26. viewer.impl.visibilityManager.show(dbIdA, modelA);
  27. viewer.setThemingColor(dbIdA, red, modelA);
  28. }
  29. for (var extIdB in listB) {
  30. if (listA[extIdB] != null) continue;
  31. var dbIdB = listB[extIdB].dbId
  32. added[extIdB] = dbIdB;
  33. console.log("Added dbId: " + dbIdB);
  34. viewer.impl.visibilityManager.show(dbIdB, modelB);
  35. viewer.setThemingColor(dbIdB, green, modelB);
  36. }
  37. for (var extId in listA) {
  38. if (typeof listB[extId] === "undefined") continue; // removed dbId
  39. var dbId = listA[extId].dbId; // should be the same as listB[extId]
  40. var propsA = listA[extId].properties;
  41. var propsB = listB[extId].properties;
  42. for (var i = 0; i < propsA.length; i++) {
  43. if (propsB[i] == null) continue;
  44. if (propsA[i].displayCategory.indexOf("__")==0) continue; // internal properties
  45. if (propsA[i].displayValue != propsB[i].displayValue) {
  46. console.log("Property " + dbId + ": " + propsA[i].displayName + " changed from "
  47. + propsA[i].displayValue + " to " + propsB[i].displayValue);
  48. modified[extId] = dbId;
  49. }
  50. }
  51. if (typeof modified[extId] != "undefined") {
  52. console.log("Modified dbId: " + dbId);
  53. // color on both models
  54. //viewer.impl.visibilityManager.show(dbId, modelA);
  55. //viewer.impl.visibilityManager.show(dbId, modelB);
  56. viewer.setThemingColor(dbId, orange, modelA);
  57. viewer.setThemingColor(dbId, orange, modelB);
  58. }
  59. }
  60. });
  61. });
  62. function listElements(callback) {
  63. getAllLeafComponents(modelA, function (modelAdbIds) {
  64. getAllLeafComponents(modelB, function (modelBdbIds) {
  65. // this count will help wait until getProperties end all callbacks
  66. var count = modelAdbIds.length + modelBdbIds.length;
  67. var modelAExtIds = {};
  68. modelAdbIds.forEach(function (modelAdbId) {
  69. modelA.getProperties(modelAdbId, function (modelAProperty) {
  70. modelAExtIds[modelAProperty.externalId] = {"dbId": modelAdbId, "properties": modelAProperty.properties};
  71. count--;
  72. if (count == 0) callback(modelAExtIds, modelBExtIds);
  73. });
  74. });
  75. var modelBExtIds = {};
  76. modelBdbIds.forEach(function (modelBdbId) {
  77. modelB.getProperties(modelBdbId, function (modelBProperty) {
  78. modelBExtIds[modelBProperty.externalId] = {"dbId": modelBdbId, "properties": modelBProperty.properties};
  79. count--;
  80. if (count == 0) callback(modelAExtIds, modelBExtIds);
  81. });
  82. });
  83. });
  84. });
  85. }
  86. function getAllLeafComponents(model, callback) {
  87. var components = [];
  88. function getLeafComponentsRec(tree, parentId) {
  89. if (tree.getChildCount(parentId) > 0) {
  90. tree.enumNodeChildren(parentId, function (childId) {
  91. getLeafComponentsRec(tree, childId);
  92. });
  93. }
  94. else
  95. components.push(parentId);
  96. return components;
  97. }
  98. var instanceTree = model.getInstanceTree();
  99. var allLeafComponents = getLeafComponentsRec(instanceTree, instanceTree.nodeAccess.rootId);
  100. callback(allLeafComponents);
  101. }
  102. return true;
  103. };
  104. VersionChanges.prototype.unload = function () {
  105. return true;
  106. };
  107. Autodesk.Viewing.theExtensionManager.registerExtension("Autodesk.Forge.Samples.VersionChanges", VersionChanges);

英文原文:https://forge.autodesk.com/bl...

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/83209.html

相关文章

  • Autodesk Forge Viewer 信息本地化技术分析

    摘要:默认情况下,是英文环境,调取的是的资源其实无需翻译。但是,如前面提到的,语言包只是包含了部分常规字串的翻译,如果遇到没有包含的常规字串怎么办呢例如,本例中的语言包并没有对,进行翻译,所以即使切换了语言,它们仍旧是英文。 注:本文是个人调试分析所得,非官方文档,请酌情选用参考。文中分析的数据由https://extract.autodesk.io转换下载而来。 谈到信息本地化,个人觉得包...

    littleGrow 评论0 收藏0
  • Forge Viewer 里切换模型视图(Viewables)

    摘要:有提供类似的功能,但这并不包含在里头。条列清单或是切换视图是非常容易的,你主要是要建立一个使用者介面让使用者去选取他们想观看的内容。我使用了来确保当前载入模型占用的内存可以都被释出。 此篇文章原作是 Autodesk ADN Philippe Leefsma,以下以我简称。 这有一个简易的博客用来说明一个我刚加入 https://forge-rcdb.autodesk.io 的一个新功...

    BlackHole1 评论0 收藏0
  • 翻译」优化 Viewer3D.search 效能

    摘要:搜索所需的时间会依据你的模型大小及你搜索字串的空白数量而定,搜索的效能差异是有可能从几秒钟有引号变成数分钟没有引号的。从上图看来,就可以知道在搜索时加上引号是怎么对效能有显著的影响。 Viewer3D.search 是一个非常有用的搜索函数,他可以让你清楚的知道你模型里面有什么信息,但他的响应时间很容易因你搜索内容而拉长。请试著想象如果我们需要进行多次的搜索,但每次都需要一段很长的时间...

    hearaway 评论0 收藏0
  • Viewer模型加载本地离线缓存实战

    摘要:本文将介绍来自顾问团队的国际同事原创的缓存范例,利用广泛用于开发的典型接口实现。因而在缓存模型时,可以调用该接口缓存所有相关的,无需用到。代码示例我们制作了让用户选择模型作离线缓存的例子,查看代码请访问,在线演示请访问。 演示视频:http://www.bilibili.com/video... 由于Autodesk Forge是完全基于RESTful API框架的云平台,且暂时没有本...

    oogh 评论0 收藏0

发表评论

0条评论

JowayYoung

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<