2015-11-06 90 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类型的注册插件进程。

干杯!