0

我在 Blender 中制作了一个场景,并将其导出为 .babylon,现在我将其导入到游戏中。地图为 351KB,我将其加载到游戏中是这样的:

var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var scene = new BABYLON.Scene(engine);
var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene);
var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene); //IMPORTANT LINE
var player_height = 2;
var player_speed = 1;
var player_inertia = 0.9;
var mouse_position = new BABYLON.Vector2(mouse_position.x, mouse_position.y);

function INIT_GAME(){

    engine.runRenderLoop(function(){ //IMPORTANT LINE
        scene.render();
    });

    canvas.height = window.innerHeight;
    canvas.width = window.innerWidth;
    canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock;
    canvas.requestPointerLock();

    scene.enablePhysics(); //IMPORTANT LINE
    scene.setGravity(new BABYLON.Vector3(0, -10, 0)); //IMPORTANT LINE

    player.attachControl(canvas, true); //IMPORTANT LINE
    player.ellipsoid = new BABYLON.Vector3(1, player_height, 1);
    player.checkCollisions = true;
    player.applyGravity = true;
    player.keysUp = [87];
    player.keysDown = [83];
    player.keysLeft = [65];
    player.keysRight = [68];
    player.inertia = player_inertia;
    player.speed = player_speed;

    window.addEventListener('resize', function(){
        engine.resize();
    });

    BABYLON.SceneLoader.Load('Scenes', 'zombie_map.babylon', engine); //IMPORTANT LINE
}

我试图将所有内容缩小到您应该查看的内容,但我将所有内容都留在那里以防万一我错过了什么。(INIT_GAME 在页面加载时加载)。我的问题是,我认为场景正在加载,但它只是给了我一个奇怪的加载图标,我认为这只是巴比伦试图在我通过它的场景中加载。我的问题是:

  • 我是否正确加载了所有内容?
  • 导入 .babylon 场景的正确格式是什么?
  • 地图的大小对于浏览器来说是否太大,如果是,我该如何压缩它?

如果您需要正面查看结果,我可以提供指向该站点的链接。告诉我,谢谢!

4

1 回答 1

1

我认为解决方案非常简单。

在您的 rootURL 之后添加一个斜杠。

所以更换

BABYLON.SceneLoader.Load('Scenes', 'zombie_map.babylon', engine); //IMPORTANT LINE

BABYLON.SceneLoader.Load('Scenes/', 'zombie_map.babylon', engine); //IMPORTANT LINE

试试这个,让我知道它是怎么回事。

于 2016-04-01T03:23:30.733 回答