2015-11-06 92 views
1

你好,我有我的項目的問題。我試圖加載我的巴比倫文件,但文件無法加載。它只顯示加載場景。 這裏是我的代碼如何加載file.babylon?它只顯示加載場景

var canvas, engine, scene, camera, score = 0; 

document.addEventListener("DOMContentLoaded", function() { 
    onload(); 
}, false); 

window.addEventListener("resize", function() { 
    if (engine) { 
     engine.resize(); 
    } 
},false); 

var onload = function() { 
    // Engine creation 
    canvas = document.getElementById("renderCanvas"); 
    engine = new BABYLON.Engine(canvas, true); 
    scene = new BABYLON.Scene(engine); 

    initGame(); 
    initScene(); 

    engine.runRenderLoop(function() { 
     scene.render(); 
    }); 

}; 

function initScene() { 


    // Create the camera 
    camera = new BABYLON.FreeCamera("camera", new BABYLON.Vector3(0,4,-10), scene); 
    camera.setTarget(new BABYLON.Vector3(0,0,10)); 
    camera.attachControl(canvas); 

    // Create light 
    var light = new BABYLON.PointLight("light", new BABYLON.Vector3(0,5,-5), scene); 

    engine.runRenderLoop(function() { 
    scene.render(); 
    }); 

} 

function initGame() { 
//BABYLON.Mesh.CreateSphere("sphere", 10, 1, scene); 
BABYLON.SceneLoader.Load("/assets/", "harimau.babylon", engine, function (newScene) { 
    // ... 
}); 
} 

這是我的代碼,我不知道怎麼用它做加載我harimau.babylon文件。 THX

回答

0

你好,你可能不得不讓你的服務器上.Babylon MIME類型

0

一個解決方案,幫助我是去你引用的Babylon.js主腳本文件,然後搜索CrossOrigin,兩條路線進行評論。然後你將不得不將你的SceneFileName.bab重命名爲SceneFileName.js

既然你的.babylon文件基本上是一個json對象,你可以跳過babylon強制的mimi類型的註冊插件進程。

乾杯!