2014-04-22 67 views
0

我有一個問題,我從JSON文件(從convert_obj_three.py創建)加載多個模型,我打算在空間中定位並在Three.js中「組合」將這些項目組合在一起,然後單獨使組合生動(也就是說,在組合模型組合後,我不需要爲組裝模型的各個部分製作動畫)。一切似乎運行良好,我沒有得到任何錯誤,但我看不到相機中的分組對象。我已經調整了我的相機設置,可能對象不在視野範圍內,但沒有任何運氣。我也已經證實,有問題的模型將單獨加載罰款。任何人都可以指出我的方向,或者可能是一個教程,代碼示例等,這將幫助我在這裏?任何意見是極大的讚賞。這裏的JS:通過JSON加載的Three.js中的模型的可見性

$(function() { 
    var group = new THREE.Object3D(), 
    renderer = new THREE.WebGLRenderer(), 
    scene = new THREE.Scene(), 
    camera = new THREE.PerspectiveCamera(45, window.innerWidth/window.innerHeight, 1, 1000), 
    loader = new THREE.JSONLoader(), 
    material = new THREE.MeshBasicMaterial({ 
     color: 0xffffff 
    }), 
    complete = 0, 
    usingPrimitives = true, 
    //usingPrimitives = false, 
    init = function() { 
     camera.position.z = 25; 
     if(usingPrimitives) { 
      var geometry = new THREE.CubeGeometry(5, 5, 5), 
      mesh1 = new THREE.Mesh(geometry, material), 
      mesh2 = new THREE.Mesh(geometry, material); 
      mesh1.position.x = -10; 
      mesh2.position.x = 10; 
      group.add(mesh1); 
      group.add(mesh2); 
      scene.add(group); 
     } else { 
      loader.load('inner.json', function(geometry) { 
       var mesh1 = new THREE.Mesh(geometry, material); 
       mesh1.position.x = -10; 
       mesh1.scale.set(1, 1, 1); 
       group.add(mesh1); 
       complete++; 
      }); 

      loader.load('outer.json', function(geometry) { 
       var mesh2 = new THREE.Mesh(geometry, material); 
       mesh2.position.x = 10; 
       mesh2.scale.set(1, 1, 1); 
       group.add(mesh2); 
       complete++; 
      }); 
      var waitForReadyInterval = setInterval(function() { 
       if(complete === 2) { 
        clearInterval(waitForReadyInterval); 
        animate(); 
       } 
      }, 50); 
     } 
     renderer.setSize(window.innerWidth, window.innerHeight); 
     document.body.appendChild(renderer.domElement); 
     animate(); 
    }, 
    animate = function() { 
     requestAnimationFrame(animate); 
     group.rotation.x += 0.01; 
     group.rotation.y += 0.02; 
     renderer.render(scene, camera); 
    }; 
    init(); 
}); 

我創建例如plunkr:http://plnkr.co/edit/fHdyHGNIPIWpl9Gr5BXK?p=preview

回答

1

您需要添加groupscene

scene.add(group); 

three.js所r.66