Javascript 知道这两种模式的区别吗?

Javascript 知道这两种模式的区别吗?,javascript,autodesk-forge,autodesk-viewer,Javascript,Autodesk Forge,Autodesk Viewer,我已经使用Autodesk rcdb项目的多模式加载程序扩展在一个查看器中获取了两个模型。现在,我正在尝试获取两个类似模型之间的差异。有什么方法可以做到这一点吗?这是我们官方博客()上的一个演示。它旨在比较ExtertAlid(Revit API的UniqueId)和属性,以区分两个模型之间的差异。大部分的工作都是通过这个扩展来完成的,希望能有所帮助 function VersionChanges(viewer, options) { Autodesk.Viewing.Extension.c

我已经使用Autodesk rcdb项目的多模式加载程序扩展在一个查看器中获取了两个模型。现在,我正在尝试获取两个类似模型之间的差异。有什么方法可以做到这一点吗?

这是我们官方博客()上的一个演示。它旨在比较ExtertAlid(Revit API的UniqueId)和属性,以区分两个模型之间的差异。大部分的工作都是通过这个扩展来完成的,希望能有所帮助

function VersionChanges(viewer, options) {
  Autodesk.Viewing.Extension.call(this, viewer, options);
}

VersionChanges.prototype = Object.create(Autodesk.Viewing.Extension.prototype);
VersionChanges.prototype.constructor = VersionChanges;

VersionChanges.prototype.load = function () {
  var modelA = this.options.modelA;
  var modelB = this.options.modelB;

  var removed = {};
  var added = {};
  var modified = {};

  var red = new THREE.Vector4(1, 0, 0, 1);
  var green = new THREE.Vector4(0, 0.5, 0, 1);
  var orange = new THREE.Vector4(1, 0.6, 0.2, 1);

  viewer.addEventListener(Autodesk.Viewing.OBJECT_TREE_CREATED_EVENT, function () {
    listElements(function (listA, listB) {
      // make all elements as ghost
      viewer.isolate(-1);
      viewer.clearThemingColors(modelA);
      viewer.clearThemingColors(modelB);

      for (var extIdA in listA) {
        if (listB[extIdA] != null) continue;
        var dbIdA = listA[extIdA].dbId;
        removed[extIdA] = dbIdA;
        console.log('Removed dbId: ' + dbIdA);
        viewer.impl.visibilityManager.show(dbIdA, modelA);
        viewer.setThemingColor(dbIdA, red, modelA);
      }

      for (var extIdB in listB) {
        if (listA[extIdB] != null) continue;
        var dbIdB = listB[extIdB].dbId
        added[extIdB] = dbIdB;
        console.log('Added dbId: ' + dbIdB);
        viewer.impl.visibilityManager.show(dbIdB, modelB);
        viewer.setThemingColor(dbIdB, green, modelB);
      }

      for (var extId in listA) {
        if (typeof listB[extId] === 'undefined') continue; // removed dbId

        var dbId = listA[extId].dbId; // should be the same as listB[extId]
        var propsA = listA[extId].properties;
        var propsB = listB[extId].properties;

        for (var i = 0; i < propsA.length; i++) {
          if (propsB[i] == null) continue;
          if (propsA[i].displayCategory.indexOf('__')==0) continue; // internal properties
          if (propsA[i].displayValue != propsB[i].displayValue) {
            console.log('Property ' + dbId + ': ' + propsA[i].displayName + ' changed from '
              + propsA[i].displayValue + ' to ' + propsB[i].displayValue);
            modified[extId] = dbId;
          }
        }

        if (typeof modified[extId] != 'undefined') {
          console.log('Modified dbId: ' + dbId);
          // color on both models
          //viewer.impl.visibilityManager.show(dbId, modelA);
          //viewer.impl.visibilityManager.show(dbId, modelB);
          viewer.setThemingColor(dbId, orange, modelA);
          viewer.setThemingColor(dbId, orange, modelB);
        }
      }
    });
  });

  function listElements(callback) {
    getAllLeafComponents(modelA, function (modelAdbIds) {
      getAllLeafComponents(modelB, function (modelBdbIds) {
        // this count will help wait until getProperties end all callbacks
        var count = modelAdbIds.length + modelBdbIds.length;

        var modelAExtIds = {};
        modelAdbIds.forEach(function (modelAdbId) {
          modelA.getProperties(modelAdbId, function (modelAProperty) {
            modelAExtIds[modelAProperty.externalId] = {'dbId': modelAdbId, 'properties': modelAProperty.properties};
            count--;
            if (count == 0) callback(modelAExtIds, modelBExtIds);
          });
        });

        var modelBExtIds = {};
        modelBdbIds.forEach(function (modelBdbId) {
          modelB.getProperties(modelBdbId, function (modelBProperty) {
            modelBExtIds[modelBProperty.externalId] = {'dbId': modelBdbId, 'properties': modelBProperty.properties};
            count--;
            if (count == 0) callback(modelAExtIds, modelBExtIds);
          });
        });
      });
    });
  }


  function getAllLeafComponents(model, callback) {
    var components = [];

    function getLeafComponentsRec(tree, parentId) {
      if (tree.getChildCount(parentId) > 0) {
        tree.enumNodeChildren(parentId, function (childId) {
          getLeafComponentsRec(tree, childId);
        });
      }
      else
        components.push(parentId);
      return components;
    }

    var instanceTree = model.getInstanceTree();
    var allLeafComponents = getLeafComponentsRec(instanceTree, instanceTree.nodeAccess.rootId);
    callback(allLeafComponents);
  }

  return true;
};

VersionChanges.prototype.unload = function () {
  return true;
};

Autodesk.Viewing.theExtensionManager.registerExtension('Autodesk.Forge.Samples.VersionChanges', VersionChanges);
函数版本更改(查看器,选项){
Autodesk.Viewing.Extension.call(此、查看器、选项);
}
VersionChanges.prototype=Object.create(Autodesk.Viewing.Extension.prototype);
VersionChanges.prototype.constructor=VersionChanges;
VersionChanges.prototype.load=函数(){
var modelA=this.options.modelA;
var modelB=this.options.modelB;
移除的var={};
var added={};
var-modified={};
var red=新的三个向量4(1,0,0,1);
绿色变量=新的三个向量4(0,0.5,0,1);
var orange=新的三个矢量4(1,0.6,0.2,1);
viewer.addEventListener(Autodesk.Viewing.OBJECT\u树\u创建的\u事件,函数(){
listElements(函数(listA、listB){
//使所有元素都成为幽灵
查看器。隔离(-1);
查看器。清除主题颜色(modelA);
查看器。清除主题颜色(modelB);
for(listA中的var extIdA){
如果(listB[extIdA]!=null)继续;
var dbIdA=listA[extIdA].dbId;
删除的[extIdA]=dbIdA;
log('removeddbid:'+dbIdA);
viewer.impl.visibilityManager.show(dbIdA,modelA);
查看器。设置主题颜色(dbIdA、红色、modelA);
}
for(列表B中的var extIdB){
如果(listA[extIdB]!=null)继续;
var dbIdB=listB[extIdB].dbId
新增[extIdB]=dbIdB;
log('Added dbId:'+dbIdB);
viewer.impl.visibilityManager.show(dbIdB,modelB);
设置主题颜色(dbIdB、绿色、modelB);
}
for(listA中的变量extId){
如果(列表的类型B[extId]=='undefined')继续;//删除了dbId
var dbId=listA[extId].dbId;//应与listB[extId]相同
var propsA=listA[extId].properties;
var propsB=listB[extId]。属性;
对于(变量i=0;i0){
tree.enumNodeChildren(parentId,function(childId){
getLeafComponentsRec(树,childId);
});
}
其他的
组件。推送(parentId);
返回组件;
}
var instanceTree=model.getInstanceTree();
var allLeafComponents=getLeafComponentsRec(instanceTree,instanceTree.nodeAccess.rootId);
回调(allLeafComponents);
}
返回true;
};
VersionChanges.prototype.unload=函数(){
返回true;
};
Autodesk.Viewing.theExtensionManager.registerExtension('Autodesk.Forge.Samples.VersionChanges',VersionChanges');

我们能否与没有与rvt模型相关属性的Obj模型进行类似的比较?恐怕这是不可能的。OBJ和RVT之间没有类似的数据。但是,您可以尝试使用将锻造碎片网格转换为实体。之后,做一些实体操作,如并集、减法、中间集等,以区分图形的差异。但这种计算复杂且耗时,它会影响你的查看器应用程序的用户体验,甚至使其崩溃。调用了three.js和csg.js之间的桥梁,这里显示了Forge Viewer上的csg.js集成。它的想法已经公布