【问题标题】:Loading Blender scene in BabylonJS在 BabylonJS 中加载 Blender 场景
【发布时间】:2016-04-01 11:44:24
【问题描述】:

我在 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 场景的正确格式是什么?
  • 地图的大小对于浏览器来说是否太大,如果是,我该如何压缩它?

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

【问题讨论】:

    标签: javascript babylonjs


    【解决方案1】:

    我觉得解决方法很简单。

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

    所以替换

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

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

    试试这个,让我知道结果如何。

    【讨论】:

    • 哎呀,我希望你是不正确的,但你是。我的菜鸟错误,谢谢!
    • 我只知道那是因为几天前我自己也犯了同样的错误:)
    猜你喜欢
    • 2019-10-01
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多