2017-08-09 167 views
0

我正在測試一些glTF分析器修改,以便根據glTF場景的三維對象層次結構構建一個實體層次結構。根據glTF模型層次結構構建器構建實體層次

它工作的很好,但是我無法從A-Frame檢查器小部件中更改a實體兒童的位置/方向/比例。只有a實體根可以被移動。

你知道缺什麼嗎?

GLTFParser.prototype.loadScenes = function() { 

    var json = this.json; 
    var extensions = this.extensions; 


    // scene node hierachy builder 
    // Geff 
    function buildNodeHierachy(nodeId, parentObject, allNodes) { 

     var _node = allNodes[ nodeId ]; 
     parentObject.add(_node); 

     if (_node.type == 'Object3D' && _node != undefined) { 
      var entityChild = AFRAME.INSPECTOR.createNewEntity({element: 'a-entity', components: {}}); 

      entityChild.setAttribute('visible', _node.visible); 
      entityChild.setAttribute('position', _node.position); 
      entityChild.setAttribute('rotation', _node.rotation); 
      entityChild.setAttribute('scale', _node.scale); 

      if(parentObject.type == 'Scene')parentObject.sceneRoot = _node; 
      entityChild.setObject3D('mesh', _node); 
      entityChild.id = _node.name; 

      //} 

      if(parentObject.el != undefined){ 
       parentObject.el.insertBefore(entityChild, null); 
       parentObject.el.emit('child-attached', entityChild); 
      } 
      _node.parent = parentObject; 
      entityChild.emit('object3dset', {object: _node, type: 'mesh'}); 
      entityChild.emit('model-loaded', {format: 'gltf', model: _node}); 
     } 


     var node = json.nodes[ nodeId ]; 

     if (node.children) { 

      var children = node.children; 

      for (var i = 0, l = children.length; i < l; i ++) { 

       var child = children[ i ]; 
       buildNodeHierachy(child, _node, allNodes); 

      } 

     } 

    } 

    return this._withDependencies 

回答

0

檢查員根本不應該參與代碼。要創建一個實體:

document.createElement('a-entity'); 

https://aframe.io/docs/0.6.0/introduction/javascript-events-dom-apis.html#creating-an-entity-with-createelement

+0

感謝,它的速度更快使用,而不是AFRAME.INSPECTOR.createNewEntity使用document.createElement時加載的模型。 – Hypergeff

+0

然後爲了讓孩子在翻譯/ roation工作,我不得不刪除行:「_node.parent = parentObject;」 – Hypergeff